Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
This presentation outlines our general product direction and should not be relied on in making a
purchase decision. This presentation is not subject to your license agreement or any other agreement
with SAP. SAP has no obligation to pursue any course of business outlined in this presentation or to
develop or release any functionality mentioned in this presentation. This presentation and SAP's
strategy and possible future developments are subject to change and may be changed by SAP at any
time for any reason without notice. This document is provided without a warranty of any kind, either
express or implied, including but not limited to, the implied warranties of merchantability, fitness for a
particular purpose, or non-infringement. SAP assumes no responsibility for errors or omissions in this
document, except if such damages were caused by SAP intentionally or grossly negligent.
Work with customers and partners to install, configure and tune SAP Sybase IQ databases
2. Query is parsed
3. Query is optimized
5. Query is executed
s IQ Query Engine
IQ Engine
u Optimization
Query execution
l Data access
t
IQ Temp Store
s IQ Main Store
2012 SAP AG. All rights reserved. 8
SQL Anywhere (SA) and SAP Sybase IQ query
execution
SA gets more involved when a query involves
Stored procedures
Procedure code is retrieved from system tables for execution in the IQ Query engine
Stored procs are recompiled and optimized for each execution
Cursors
Invokes row-by-row processing between SA and the IQ query engine
* Does NOT apply to Partner UDF libraries added the SAP Sybase IQ libraries
For performance reasons avoid using Cursors when many rows need to be processed
Try to leverage the IQ engine whenever possible
Use Set Logic or Case statements rather than Cursors
For Example:
Use a series of Update commands with a Where clause to modify values in specific rows
s
Temp Store Main Store
2012 SAP AG. All rights reserved. 12
Query parallelism in IQ 15
15.3 Added distributed query parallelism across others servers in IQ Multiplex (PlexQ)
Also added additional query operators eligible for parallel execution
HTML Query Plans illustrate parallel operations and the degree of parallelism
Introduced later in this presentation
SAP Sybase IQ maintains the ability to support many concurrent users but can take
advantage of an idle server
A big query running alone might use many or all cores
SAP Sybase IQ 15.x - Decoding is delayed until actual data values are absolutely required
Tokens are manipulated rather than data values reducing memory usage
Using tokens reduces memory requirements for these operations (often significantly)
Query performance changes in SAP Sybase IQ 15 are highly visible in query plans and show:
Operations performed in parallel
Thread and CPU utilization
Details in query timing
Use these options for creating graphical (html) query plans on the IQ Server
Query_Plan_As_HTML_Directory = <dir_name>
Sets a server side directory for HTML query plans
This is optional but recommended
See Appendix 3 for database options to access client side graphical query plans
Query Text
Query Tree
Node Detail
Timing Histogram
Threads
CPU Utilization
Node Number
Node Type
Number of rows
flowing up the tree
Node depth
varies with
2012 SAP AG. All rights reserved. thread count 33
Query Timing Histogram and Wall Time
Depicts time expended at each node
Wall clock
In IQ Multiplex environments some query operations can be distributed to other nodes (PlexQ)
Not all queries will qualify for distribution
The node where the query is submitted is the Leader node
Other nodes used with distributed processing are considered Worker nodes
Query plans for distributed queries reflect the work performed on all participating nodes
A query plan fragment is created for each worker node
Fragment 4
Fragment 1 Sort Merge Join
Sort operation
Fragment 2 Fragment 3
Sort operation Sort Merge Join
Fragment 2
Fragment 3
Fragment 4
Parent Node
Node that called this node
Link to that Node
Result Rows
Generated: Actual rows from this node
Estimate: Optimizers estimate of rows from this node
Output Details
Data type and number of distinct values (Base Distinct) for each output column
Leaf Node outputs provide additional details including index type and index advice (if enabled)
Root Leaf
Filter Subquery
Number of CPUs
Cache sizes
Number of CPUs
The number of CPUs the IQ engines believes are available
With hyper-threaded CPUs or -iqnumbercpus server parameter is set the number of cpus may not match actual
number on the server
Cache sizes
A reminder how large the caches are
Database Options
Options set to non-default values affecting query performance or behavior are displayed with their
current value
* Invariant predicate
A predicate with a constant value(s) throughout the life of the query
Example: customer_state IN (CA, NV, DC)
Scrolling Cursor Store node usually found just below the Root Node
Affected by the database option Force_No_Scroll_Cursors (default ON)
(Regular) Leaf
Aggregation Leaf
Grouping Leaf
Distincting Leaf
Ordered Leaf
Proxy Leaf (Proxy Table)
SA Leaf (table in the SA database)
All column metadata needed by the optimizer is identified in the Leaf node
Row Counts
Total rows in the table
Estimated count after executing all conditions
Generated count after executing all conditions
Rows Counts
Total rows in the table
Generated rows after conditons (if any)
Conditions (Predicates)
Selectivity
Usefulness
Elapsed time (to execute)
Rows remaining (post execution)
Index used
Threads used
Selectivity
Portion (percentage) of the table rows that satisfy that predicate
HG, LF and FP indexes provide this metadata
Usefulness Score
The order the predicates have been executed
Execution phase, cost and resources required influence Usefulness scoring
Percent of table
Predicate Type (Estimated) Selectivity
Equality (=) 20% 0.2000000
Open Range (>) 40% 0.4000000
Between 40% 0.4000000
Like (%) 20% 0.2000000
Inter-column equality (t.a = t.b) 30% 0.3000000
Inter-column comparison (t.a < t.b) 50% 0.5000000
Note: Some functions can negate the ability to use an index for selectivity
Example: SUBSTRING( t.a, 5, 5 ) = homes
Optimizer might use default electivity
20% for an equality search ( .20000000)
Category is based upon when the data required for predicate execution is available
Predicate category usually dictates the phase (i.e. timing) when it is executed in the query
Invariant predicates are usually executed in an early phase to ensure accurate row count
information is available to subsequent phases of query optimization
These are predicates that need to be executed once but require information that will become
available after another part of a query is executed:
The Where cust_id in predicate is delayed since the subquery must be executed first
Delayed predicates are typically found with uncorrelated subqueries (above) and some Push-Down joins
Bound predicates
Need to be executed repeatedly and require information that will only be available after some other portion of the
query has been executed
Note: Execution phase can be user influenced by using Optimizer Hints written into query code
Ranges ( <, >, <=, >=, Between) including NOT Between DATE, HNG,
LF and HG
Range searches are costed by the optimizer to determine which index is appropriate
Cost estimates are provided for different index types (even if they dont exist on the column)
Except for special cases the other IQ indexes are used to locate values and do not provide
metadata
Only the LF, HG and FP indexes provide metadata
Grouping Leaf
SELECT MEMBER_GENDER, COUNT(*)
FROM
GROUP BY MEMBER_GENDER
Distincting Leaf
SELECT DISTINCT (shipdate)
FROM
Leaf nodes provide a wealth of information about the data and indexes used in a query
Index advice
Join nodes merge a set of rows from one table with rows from another table passing all
combinations which satisfy the join condition(s)
Individual columns which are primary keys always declare as a PRIMARY KEY
(or create a UNIQUE HG index)
Candidate key columns create a UNIQUE HG index if used in joins
Multi-column primary keys where tables will be joined using all the keys create a multi-column
PRIMARY KEY (or a multi-column UNIQUE HG index)
If all keys are NOT used in a Join then a Primary Key (or multi-column Unique index) is not necessary
For example, the Primary Key for a Fact table would almost never be necessary (except to maintain entity
integrity)
Valid algorithms are compared against each other based on their estimated costs and available
server resources
Knowledge of the join algorithms, their strengths and weaknesses, may allow you to identify
ways you could change the query or the schema to improve query performance
These join algorithms are used in SAP Sybase IQ (as well as most relational databases):
Nested Loop
Hash
Sort-Merge
Advantages:
Used with any type of join condition, even LIKE join conditions (or with no join conditions at all)
Used with every type of OUTER JOIN
Disadvantages:
If small side has more than a couple rows (1 or 2) then this join may be very slow
Constraints:
Small side row store uses Temp Cache
Advantages:
Is fast, when appropriate
Used for any kind of INNER or OUTER JOIN
Disadvantages:
Requires at least one equality join condition where both join columns are identical data types
A data type mismatch of join columns will disqualify Hash joins (index advisor reports type mismatches)
Constraints:
The small side must fit within available and pinnable Temp Cache
Pinnable hash buffers in memory cannot be paged to swap
sort sort
T1 T2
Advantages:
Is fast and when it can be parallelized
Can be used for any kind of INNER or OUTER JOIN
Disadvantages:
Requires at least one equality join condition
Constraints:
Both join inputs must be sorted within the temp cache
Can consume large amounts of temp cache space
Modest performance penalty if sort set cannot remain entirely within Temp Cache
Parallel Sort
Data flow
Pushdown joins reduce join work by filtering rows in one table using the keys of a smaller table
like an In List predicate
In cases of multi-table queries filtering may be performed several nodes below where the actual join occurs
When the optimizer uses a Push Down join, you will see an additional =, IN, or
PROBABLY_IN predicate in the Leaf Node being filtered
Optimization Notes
Merges a set of rows from one table into a smaller number of output rows
Each row represents collective information from one or more input rows
Group By (Single)
1 result row, no Group By clause
If you have > 4 GB of memory consider modifying database options for Hashes
Default values for these options are based on a server with 4 GB RAM
Improve chances of the optimizer using Hashes by modifying these Database Options:
Max_Hash_Rows - default value = 2,500,000 (keys)
Hash_Pinnable_Cache_Percent - default Value = 20 (percent)
Optimizer considers hash algorithms based upon available Temp Cache and the number of
hash keys expected
Number of hash keys is reported in Join nodes
If number of keys is less than Max_Hash_Rows option value a hash may be chosen
Sets the percentage of a users Temp Cache memory allocation that any one Hash object can
pin in memory
Dynamically configurable
The optimizer evaluates the size and availability of the IQ Temp Cache to determine whether to
use hash Group By
Max_Hash_Rows is still considered for joins but should be used with caution
It may cause the optimizer to use hash joins with non-parallel components
Sort-Merge joins which can fully parallelized can be faster but might not be chosen when Max_Hash_Rows is high
IQ server parameter gm (max user connections) affects individual users memory allocation
The IQ memory manager sets aside memory to accommodate all possible connections based on gm
The higher the value of gm, the lower the users memory allocation
Have a plan before you start modifying database options and memory
Before we close
Why does Sybase usually recommend the Temp Cache be larger than Main Cache?
Hashes
Hash Joins (HJ, HPDJ)
Group By (Hash)
NLPD Joins Sorts
Sort Joins (SMJ, SMPDJ)
Correlated Subqueries Group By (Sort)
Order By
Nested Loop Joins (NLJ)
IQ IQ
Store Temp
2012 SAP AG. All rights reserved. Store 107
Questions
big
table
Advantages:
Is very fast, when appropriate
Can be used for INNER JOIN or RIGHT OUTER JOIN
Disadvantages:
The large side of the join must be a single table
Requires an equality join condition
Column from the large table needs HG or LF index
Constraints:
If small side is more than a few rows, then all projected columns from large side must fit within the Main Cache or
performance will be very slow
T1 T2 T3 T4
By filtering T1 with keys from J3 there
is less work to be done in J1 and J3
2012 SAP AG. All rights reserved. 112
Hash Pushdown Join
Advantages:
Is very fast, when appropriate
Can be used for INNER JOIN or RIGHT OUTER JOIN
Disadvantages:
Requires equality join condition where both sides are identical data types
Expression from the large side must be column with an LF or HG index
Constraints:
The small side must fit within available Temp Cache
T1 T2 T3 T4
Advantages:
Can be used for INNER JOIN or RIGHT OUTER JOIN
Disadvantages:
Requires equality join condition
Both sides are identical data types
Expression from large side must be column with LF/HG index
Constraints:
Both join inputs passed through sorts in Temp Cache
Must be sufficient Temp cache space to pin the entire bit vector
Two methods:
Database Options (usually set as a Temporary Option)
Optimizer Hints hard coded in SQL
You can only influence the join type from the list of valid join algorithms in the Query
Plan (join node), otherwise the option will be ignored by the optimizer
2012 SAP AG. All rights reserved. 120
Example: Join_Preference Option
Join_Optimization Default: ON
Switching option OFF parses table joins from left to right as specified in the From clause
May help an individual query but should only be used if you are certain the optimizer has misjudged the query
You may want to use parenthesis in the FROM clause to ensure you are getting the desired join order
One of the obvious problems using the Join_Preference option is the global scope and
potential to affect other joins in a query
Using the database option might help one join but could all other joins in the query
Optimizer hints were introduced to allow hard coding of join preference * in SQL code
More granular than using the join_preference option
These hints are useful for coding into canned SQL code and stored procedures
* Hints can also be used to suggest indexes, selectivity and execution phase. See the IQ reference Manual.
Simple equality join predicates can be tagged with a predicate hint allowing a join preference to
be specified for just that join
The following example requests a Hash Join:
Select
FROM customers c, orders o
WHERE (c.cust_key = o.cust_key , J:4 )
Syntax
Enclose the entire join clause and hint within parentheses
Comma precedes the J:_ hint
Use the same positive or negative numbers for the Join_Preference database option to specify the desired join type
Use these Database Options and Functions to retrieve query plans at client workstations
Database Options
Query_Plan_Text_Access = ON (default = Off)
Allows access to query plans with dbisql (java) client
SQL Functions
HTML_Plan()
Returns an HTML query plan file to a client
Graphical_Plan()
Returns XML query plan file to a client
No part of this publication may be reproduced or transmitted in any form or for any purpose without the Google App Engine, Google Apps, Google Checkout, Google Data API, Google Maps, Google Mobile Ads,
express permission of SAP AG. The information contained herein may be changed without prior notice. Google Mobile Updater, Google Mobile, Google Store, Google Sync, Google Updater, Google Voice,
Google Mail, Gmail, YouTube, Dalvik and Android are trademarks or registered trademarks of Google Inc.
Some software products marketed by SAP AG and its distributors contain proprietary software components
of other software vendors. INTERMEC is a registered trademark of Intermec Technologies Corporation.
Microsoft, Windows, Excel, Outlook, PowerPoint, Silverlight, and Visual Studio are registered trademarks of Wi-Fi is a registered trademark of Wi-Fi Alliance.
Microsoft Corporation.
Bluetooth is a registered trademark of Bluetooth SIG Inc.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z,
System z10, z10, z/VM, z/OS, OS/390, zEnterprise, PowerVM, Power Architecture, Power Systems, Motorola is a registered trademark of Motorola Trademark Holdings LLC.
POWER7, POWER6+, POWER6, POWER, PowerHA, pureScale, PowerPC, BladeCenter, System Storage, Computop is a registered trademark of Computop Wirtschaftsinformatik GmbH.
Storwize,
XIV, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, AIX, Intelligent Miner, WebSphere, SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP BusinessObjects Explorer, StreamWork,
Tivoli, Informix, and Smarter Planet are trademarks or registered trademarks of IBM Corporation. SAP HANA, and other SAP products and services mentioned herein as well as their respective logos are
trademarks or registered trademarks of SAP AG in Germany and other countries.
Linux is the registered trademark of Linus Torvalds in the United States and other countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions,
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are trademarks or registered trademarks of Adobe Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as
Systems Incorporated in the United States and other countries. their respective logos are trademarks or registered trademarks of Business Objects Software Ltd. Business
Oracle and Java are registered trademarks of Oracle and its affiliates. Objects is an SAP company.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere, and other Sybase products and
services mentioned herein as well as their respective logos are trademarks or registered trademarks of
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or Sybase Inc. Sybase is an SAP company.
registered trademarks of Citrix Systems Inc.
Crossgate, m@gic EDDY, B2B 360, and B2B 360 Services are registered trademarks of Crossgate AG
HTML, XML, XHTML, and W3C are trademarks or registered trademarks of W3C, World Wide Web in Germany and other countries. Crossgate is an SAP company.
Consortium, Massachusetts Institute of Technology.
All other product and service names mentioned are the trademarks of their respective companies. Data
Apple, App Store, iBooks, iPad, iPhone, iPhoto, iPod, iTunes, Multi-Touch, Objective-C, Retina, Safari, Siri, contained in this document serves informational purposes only. National product specifications may vary.
and Xcode are trademarks or registered trademarks of Apple Inc.
The information in this document is proprietary to SAP. No part of this document may be reproduced,
IOS is a registered trademark of Cisco Systems Inc. copied,
or transmitted in any form or for any purpose without the express prior written permission of SAP AG.
RIM, BlackBerry, BBM, BlackBerry Curve, BlackBerry Bold, BlackBerry Pearl, BlackBerry Torch, BlackBerry
Storm, BlackBerry Storm2, BlackBerry PlayBook, and BlackBerry App World are trademarks or registered
trademarks of Research in Motion Limited.
2012 SAP AG. All rights reserved. 129