DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Low-Code Development: Leverage low and no code to streamline your workflow so that you can focus on higher priorities.

DZone Security Research: Tell us your top security strategies in 2024, influence our research, and enter for a chance to win $!

Launch your software development career: Dive head first into the SDLC and learn how to build high-quality software and teams.

Open Source Migration Practices and Patterns: Explore key traits of migrating open-source software and its impact on software development.

Related

  • Query SQL and NoSQL Databases Using Artificial Intelligence
  • Snowflake Data Time Travel
  • SQL Server From Zero To Advanced Level: Leveraging nProbe Data
  • How To Work Effectively With JDBC in Java Scripts

Trending

  • The Rise of Kubernetes: Reshaping the Future of Application Development
  • Setting up Device Cloud: A Beginner’s Guide
  • The Cutting Edge of Web Application Development: What To Expect in 2024
  • Implementing Real-Time Credit Card Fraud Detection With Apache Flink on AWS
  1. DZone
  2. Data Engineering
  3. Databases
  4. Diagnosing and Optimizing Running Slow SQL in GBase 8s Database

Diagnosing and Optimizing Running Slow SQL in GBase 8s Database

This article will discuss how to check for running slow SQL queries, as well as provide corresponding optimization strategies.

By 
Cong Li user avatar
Cong Li
·
Jul. 05, 24 · Tutorial
Like (1)
Save
Tweet
Share
1.7K Views

Join the DZone community and get the full member experience.

Join For Free

Detecting and optimizing slow SQL queries is a critical step in enhancing database performance during routine maintenance. Slow SQL queries not only impact user experience but can also become a source of system performance bottlenecks. This article will discuss how to check for running slow SQL queries and provide corresponding optimization strategies.

1. Using SQL Queries To Detect Slow SQL

1.1. Basic SQL Querying

By running specific SQL queries, you can quickly identify high-cost, potentially slow-executing SQL statements. This provides a basis for further analysis and optimization.

SQL
 
dbaccess sysmaster -<<!
select first 10 sqx_estcost,
sqx_estrows, sqx_sessionid,
sqx_sqlstatement
from sysmaster:syssqexplain
where 1=1
order by sqx_estcost desc;
!


1.2. Analyzing Query Output

Analyze the query results to identify SQL statements with the highest estimated cost and row count. These statements are often the primary targets for optimization efforts.

SQL
 
sqx_estcost       2147483647
sqx_estrows       49
sqx_sessionid     51
sqx_sqlstatement  select max(t3.tabid) as id from systables t1,systables t2,sys
                  tables t3, systables t4,systables t5,systables t6
group by t
                  1.tabname,t2.tabname


1.3. Interpreting Output

Understand the meaning of each field in the output, such as estimated cost (sqx_estcost), estimated rows (sqx_estrows), session ID (sqx_sessionid), and the SQL statement itself (sqx_sqlstatement).

2. Using Commands To Check Running Slow SQL

2.1. Check Continuously Running Threads (rstcb)

Identify threads with a constant third column in the output, indicating ongoing execution.

SQL
 
onstat -g act -r 1 | egrep "sqlexec|threads"


Output:

SQL
 
Running threads:
 215     4a645178         470f33e8         1   running                 8cpu         sqlexec
Running threads:
 215     4a645178         470f33e8         1   running                 8cpu         sqlexec


2.2. View Thread Sessions

Based on the previous output, inspect thread information.

SQL
 
onstat -u |grep 470f33e8


Output:

SQL
 
470f33e8         ---P--- 51       gbasedbt -        0                0    1    5        0


2.3. Check Session Information

From the previous step, examine session information and the executing SQL.

SQL
 
onstat -g ses 51


Output:

SQL
 
On-Line -- Up 14 days 19:53:19 -- 674664 Kbytes

session           effective                            #RSAM    total     used       dynamic
id       user    user      tty      pid     hostname threads  memory     memory    explain
51       gbasedbt -         -        1486    dbhost1  1        221184     218648    off

Program :
/opt/gbase/bin/dbaccess

tid      name    rstcb            flags    curstk  status
215      sqlexec 470f33e8         ---P---  10528   running-

Memory pools    count 2
name         class addr              totalsize  freesize  #allocfrag #freefrag
51           V    4a745040         217088     1728      453        6
51*O0        V    4a788040         4096       808        1          1

name           free       used          name           free       used
overhead       0          6576           scb            0          144
opentable      0         9192           filetable      0         904
log            0          16536          temprec        0          22688
keys           0          176            ralloc         0          80024
gentcb         0          1616           ostcb          0          2968
sqscb          0          21064          sql            0          18952
hashfiletab    0         552            osenv          0          2768
sqtcb          0          9688           fragman        0          1240
shmblklist     0         22568          rsam_seqscan   0         992

sqscb info
scb              sqscb            optofc   pdqpriority optcompind  directives
47b61290         4a735028         0        0           2           1

Sess       SQL            Current            Iso Lock       SQL ISAM F.E.
Id         Stmt type      Database           Lvl Mode       ERR ERR  Vers  Explain
51         SELECT        testdb             LC Not Wait   0    0   9.24  Off

Current statement name : unlcur

Current SQL statement (2) :
  select max(t3.tabid) as id from systables t1,systables t2,systables t3,
    systables t4,systables t5,systables t6  group by t1.tabname,t2.tabname

Last parsed SQL statement :
  select max(t3.tabid) as id from systables t1,systables t2,systables t3,
    systables t4,systables t5,systables t6  group by t1.tabname,t2.tabname


By checking and analyzing running slow SQL queries, we can more accurately identify performance bottlenecks and take appropriate optimization measures. Whether using SQL queries or system commands, the key is to understand the output results and develop optimization strategies accordingly.

Database sql

Published at DZone with permission of Cong Li. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Query SQL and NoSQL Databases Using Artificial Intelligence
  • Snowflake Data Time Travel
  • SQL Server From Zero To Advanced Level: Leveraging nProbe Data
  • How To Work Effectively With JDBC in Java Scripts

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: