Professional Documents
Culture Documents
Lou Stanton
Principal System Consultant
stanton@sybase.com / (301) 896-1733
August 2003
Query Processing and Query Plans
In this presentation -
Show you how Sybase IQ Processes Queries
Show methods for viewing Query Plans
Understanding and Interpreting Query Plans
How to influence Query Execution
Discuss general Performance and Tuning tips
You’re not sure you have the best indexes for a query
Query plans tell you what indexes are used in a query
Query Execution Phases in Sybase
1) Query Tree
2) Query Detail
HTML Query Plan – The Query Tree
Estimated Rows
Moving Up the Tree
Node Type
And Number
Leaf Nodes
Nodes - General
Root Join
Scrolling Cursor Store Hash (HJ)
Filter Hash Pushdown (HJPD)
Group By
Nested Loop (NL)
Sort
Nested Loop Pushdown
(NLPD)
Hash
Sort-Merge (SM)
Indexes
Sort-Merge Pushdown
Order By (SMPD)
Store Cartesian
Semi-join Filter Filler Subquery
Leaf Union All
Node Details
Nodes to Concentrate On -
Root
Leaf
Join
Group By
Filter
Root Node (only with Query_Detail = ‘ON’)
Node Detail
• Child Node
• Query Name (if any)
• User Name (login)
• Temp Space Used
• Num of Users in Server
• Num of CPUs
select paid_amt
from central_fact_table
Where elig_beg_date >= '2000-01-01' and
MEMBER_GENDER = 'M' and
MEMBER_DOB < '1950-01-01' and
complication = 'OUTPATIENT' and
service_rollup = 'Neoplasms'
Optimizer Search Criteria – NO indexes
Percent of table
Query Operator Returned (Estimated)
Equality (=) 20%
Open Range (>) 40%
Between 40%
Like (%) 20%
Inter-column equality (t.a = t.b) 30%
Inter-column comparison (t.a < t.b) 50%
(You will see these estimates in Query Plans)
Leaf Node Discussion–Indexes on Predicates
IS [NOT] NULL
Query Predicate Operators and IQ Indexes
select paid_amt
from central_fact_table
Where
elig_beg_date >= '2000-01-01' and
MEMBER_GENDER = 'M' and
MEMBER_DOB < '1950-01-01' and
complication = 'OUTPATIENT' and
service_rollup = 'Neoplasms'
The Leaf Node for This Query
This is a large
Leaf Node !
(about 2 pages)
We will examine
it in parts
Leaf Node (Part 1) Row Information
Selectivity
Usefulness
Index Used
Usefulness For Each Predicate Assigned
Row Estimate
Off by a factor or 72.6
Temp Space Usage
Just slightly below actual
Questions …
Why is row estimate wrong?
Is this a problem?
Row Estimates
You will see the Full Join Type Names and Abbreviations in
Query Plans
Child Nodes
Estimated Result Rows
Join Types Considered
Optimization Note
Join Constraint
‘Push Down’ Joins
New Estimate
24,396,774,363
300,000 x
smaller!
Tweaking Joins
Group By (Hash)
Same database options apply as for joins
2,500,000 row max (default)
Group By Nodes - General
No HG/LF Index !
Node Detail –Group By (Hash)
Node detail – Filter Node
Index on Group By Column May Help
Visit the
IQ Technical Team
on the Boardwalk
Lou Stanton
stanton@sybase.com