SlideShare a Scribd company logo
1 of 82
Download to read offline
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
ISUG-TECH 2015 ConferenceISUG-TECH 2015 Conference
Pr esent er ’ s Sessi on Ti t l e her ePr esent er ’ s Sessi on Ti t l e her e
Pr esent er ’ s namePr esent er ’ s name
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
AgendaAgenda
Welcome
Speaker Introduction
Session Title (add presentation title)
Q&A
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Jeff GarbusJeff Garbus
Speaker(s) should add a few introductory
commentsabout him/herself
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Single – Table Optimization
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Acknowledgements
Sybase Adaptive Server is a
trademark of Sybase Inc.
This presentation is
copyrighted.
This presentation is not for re-
sale
This presentation shall not be
used or modified without
express written consent of
Soaring Eagle Consulting,
Inc.
Slide 6 - 5
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Examine detailed topics in query optimization
Indexes with SARGs
Improvised SARGs
Clustered vs. nonclustered Indexes
Queries with OR
Index covering
Forcing index selection
Partition support
Slide 6 -
Single - Table Optimization
Topics
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Table scans
Index searches
Covered index searches
Slide 6 - 7
Adaptive Server Search Techniques
ASE uses three basic search techniques for
query resolution
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Scans are expensive
Table scans may be planned even if the rest of
the query is false!
Slide 6 - 8
Table Scans
If Adaptive Server can’t resolve a query any
other way, it does a table scan
Identify table scan searches
select * from pt_tx where 1 = 2
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 9
Table Scans
select * from pt_tx where 1=2
SHOWPLAN OUTPUT
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 10
Table Scans Continued
SHOWPLAN OUTPUT
QUERY PLAN FOR STATEMENT 1 (at line 1).
STEP 1
The type of query is SELECT.
2 operator(s) under root
|ROOT:EMIT Operator
|
| |RESTRICT Operator
| |
| | |SCAN Operator
| | | FROM TABLE
| | | pt_tx
| | | Table Scan.
| | | Forward Scan.
| | | Positioning at start of table.
| | | Using I/O Size 16 Kbytes for data pages.
| | | With LRU Buffer Replacement Strategy for data pages.
select * from pt_tx where 1=2
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 11
Table Scans
DBCC TRACEON (3604, 302,
select * from pt_tx where 1=2
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 12
Table Scan Output: SELECT
select *
from pt_tx
SHOWPLAN
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 13
Table Scan Output: SELECT
select *
from pt_tx
SHOWPLAN
STEP 1
The type of query is SELECT.
1 operator(s) under root
|ROOT:EMIT Operator
|
| |SCAN Operator
| | FROM TABLE
| | pt_tx
| | Table Scan.
| | Forward Scan.
| | Positioning at start of table.
| | Using I/O Size 16 Kbytes for data pages.
| | With LRU Buffer Replacement Strategy for data pages.
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 14
Table Scan Output: UPDATE
update pt_tx
set id = id + 1
SHOWPLAN OUTPUT
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 15
Table Scan Output: UPDATE
update pt_tx
set id = id + 1
SHOWPLAN OUTPUT
STEP 1
The type of query is UPDATE.
2 operator(s) under root
|ROOT:EMIT Operator
|
| |UPDATE Operator
| | The update mode is direct.
| |
| | |SCAN Operator
| | | FROM TABLE
| | | pt_tx
| | | Table Scan.
| | | Forward Scan.
| | | Positioning at start of table.
| | | Using I/O Size 16 Kbytes for data pages.
| | | With LRU Buffer Replacement Strategy for data pages.
| |
| | TO TABLE
| | pt_tx
| | Using I/O Size 2 Kbytes for data pages.
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Use SET STATISTICS IO ON to verify what actually happens
when the query executes
Slide 6 - 16
Optimization vs. Execution
Scans planned at optimization may not happen
update pt_tx set id = id + 1
Example 1 (scan planned and executed)
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
STATISTICS IO OUTPUT
Slide 6 - 17
Optimization vs. Execution
Slide 2 of 5
update pt_tx set id = id + 1
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
STEP 1
The type of query is UPDATE.
2 operator(s) under root
|ROOT:EMIT Operator
|
| |UPDATE Operator
| | The update mode is direct.
| |
| | |SCAN Operator
| | | FROM TABLE
| | | pt_tx
| | | Table Scan.
| | | Forward Scan.
| | | Positioning at start of table.
| | | Using I/O Size 16 Kbytes for data pages.
| | | With LRU Buffer Replacement Strategy for data pages.
| |
| | TO TABLE
| | pt_tx
| | Using I/O Size 2 Kbytes for data pages.
STATISTICS IO OUTPUT
Slide 6 - 18
Optimization vs. Execution
update pt_tx set id = id + 1
Table: pt_tx scan count 1, logical reads: (regular=6 apf=0 total=6), physical
reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: pt_tx scan count 0, logical reads: (regular=0 apf=0 total=0), physical
reads: (regular=0 apf=0 total=0), apf IOs used=0
Total writes for this command: 9
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 19
Optimization vs. Execution
update pt_tx
set id = id + 1
where 1 = 2
SHOWPLAN
Example 2 (scan planned but not executed)
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
STEP 1
The type of query is UPDATE.
2 operator(s) under root
|ROOT:EMIT Operator
|
| |UPDATE Operator
| | The update mode is direct.
| |
| | |SCAN Operator
| | | FROM TABLE
| | | pt_tx
| | | Table Scan.
| | | Forward Scan.
| | | Positioning at start of table.
| | | Using I/O Size 16 Kbytes for data pages.
| | | With LRU Buffer Replacement Strategy for data pages.
| |
| | TO TABLE
| | pt_tx
| | Using I/O Size 2 Kbytes for data pages.
Slide 6 - 20
Optimization vs. Execution
update pt_tx
set id = id + 1
where 1 = 2
SHOWPLAN
Example 2
(scan planned but not executed)
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
In this example, the optimizer still plans a table scan
even though the WHERE clause short-circuits the
query at execution time
Use STATISTICS IO output to verify a scan really
happened
Slide 6 - 21
Optimization vs. Execution
Continued
STATISTICS
Table: pt_tx scan count 1, logical reads: (regular=6 apf=0 total=6), physical reads: (regular=0 apf=0
total=0), apf IOs used=0
Table: pt_tx scan count 0, logical reads: (regular=0 apf=0 total=0), physical reads: (regular=0 apf=0
total=0), apf IOs used=0
Total writes for this command: 9
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
 Index types
 Optimizer selection criteria
 When indexes slow
access
 Index statistics and usage
Slide 6 - 22
Index Selection
Topics
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
ASE provides three types of indexes
Clustered
Nonclustered
Full text
One clustered index per table
Data is maintained in clustered index order
248 nonclustered indexes per table
Nonclustered indexes maintain pointers to rows
Full text indexing is beyond scope
Slide 6 - 23
Index Types
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Indexes are balanced b-tree structures
An index may contain between 1 and 31 columns, but the
total index entry width must be no greater than
600 bytes
Text, image and bit columns can be indexed
Indexes are maintained and used internally by the server
to improve performance or to enforce uniqueness
The application programmer does not usually refer to
indexes
Slide 6 - 24
Index Types
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Here, we’re clustered
on last name
With a clustered
index, there will be
one entry on the
last intermediate
index level page
for each data page
The data page is the
leaf or bottom
level of the index
Slide 6 - 25
Clustered Index Mechanism
Houston
Exeter
Brown
Albert
Quincy
Mason
Jones
Albert
Loon
Klein
Jude
Jones
Paul
Parker
Neenan
Mason
Alexis, Amy, ...
Root Page
Intermediate Page
Data Page
Amundsen, Fred, ...
Baker, Joe, ...
Best, Elizabeth, ...
Albert, John, ...
Masonelli, Irving, ...
Narin, Mabelle, ...
Naselle, Juan, ...
Neat, Juanita
Mason, Emma, ...
...
...
...
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
 Here, we have a
nonclustered
index on first
name
 The nonclustered
index has an
extra, leaf level
for
page / row
pointers
 Nonclustered
indexes do not
affect data
placement
Slide 6 - 26
Nonclustered Index Mechanism
Dave
Bob
Amy
Zelda
Elizabeth
Elizabeth
George
George
Amy
...
...
...
...
...
...
Sam
Sam
Alexis, Amy, ...
Root Page
Intermediate Page
Data Page
Amundsen, Fred, ...
Baker, Joe, ...
Best, Elizabeth, ...
Albert, John, ...
Masonelli, Irving, ...
Narin, Anabelle, ...
Naselle, Amy, ...
Neat, Juanita
Mason, Emma, ...
Zelda
...
...
...
Amy
Amy
...
...
Emma
...
Leaf Page
Anabelle
...
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
A clustered index tends to be 1 I/O faster than a
nonclustered index for a single-row lookup
Clustered indexes are excellent for retrieving ranges of
data
Clustered indexes are excellent for queries with
order by
Nonclustered indexes are a bit slower, take up much more
disk space, but are usually the next best alternative to a
table scan
Nonclustered indexes may cover the query for maximal
retrieval speed; For some queries; covered queries,
nonclustered indexes can be faster
Slide 6 - 27
Clustered vs. Nonclustered
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
A primary key is a logical concept, not a physical concept
Indexes are physical concepts, not logical concepts
There is a strong correlation between the logical concept of a key and the
physical concept of an index
By default, when you define relationships as part of table design, you will
build indexes to support the joins / lookups
By default, when you define a primary key, you will create a unique
clustered index on the table
Unique is good, clustered isn’t always good
Primary Key vs. Clustered
vs. Nonclustered
Page 6 - 28
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
During the index selection phase of optimization the
optimizer decides which (if any) indexes best
resolve the query
o Identify which indexes match the where clauses
o Estimate rows to be returned
o Estimate page reads
Slide 6 - 29
Optimizer Selection Criteria
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
 Indexes must correspond with SARGs.
 Useful indexes will specify a row or rows or set bounds for the
result set
 An index may be used if at least the first column of the index
matches the SARG
where dob between
'3/3/1941' and '4/4/65'
Slide 6 - 30
SARG Matching
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Which of the following queries (if any) is helped by the index?
select * from authors
where au_fname = 'Jim' and au_lname = 'Smith‘
select * from authors where au_fname = 'Jim‘
select * from authors
where au_lname = 'Smith' or au_fname = 'Jim'
Slide 6 - 31
SARG Matching (Continued)
Create index a on authors(au_lname, au_fname)
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Columns searched by range of values
Columns by which the data is frequently sorted (order
by or group by)
Sequentially accessed columns
Join columns (if other than the primary key)
Static columns
Slide 6 - 32
Using Indexes
Clustered Index Indications
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
NCI selection tends to be much more effective if less than
about 10% of the data is to be accessed (documentation
says 20%, it is wrong)
NCIs help sorts, joins, group by clauses, etc., if other
column(s) must be used for the CI
Index covering
Slide 6 - 33
Using Indexes
Nonclustered Index
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
The server can use the leaf level of a nonclustered index the way it
usually reads the data pages of a table: this is index covering.
The server can skip reading data pages
The server can walk leaf page pointers
A nonclustered index will be faster than a clustered index if the index
covers the query for a range of data (why?)
Adding columns to nonclustered indexes is a common method of
reducing query time
This has particular benefits with aggregates
Slide 6 - 34
Index Covering
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Beware making the index too wide; As index width approaches row
width, the benefit of covering is reduced
# of levels in the index increases
Index scan time approaches table scan time
Remember that changes to data will cascade into indexes
Over-indexing can cause OLTP performance problems
Slide 6 - 35
Index Covering Continued
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
 What index will optimize this
query?
 What index will optimize this
query?
 In the second query, what
would the net effect be of
changing the range to this?
select title
from titles
where title = 'Future
Shock'
Slide 6 - 36
Index Selection Examples
select title
from titles
where price
between $5. and $20.
between $500 and $600
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
2,000,000 titles
40 rows / page (=50,000 pages)
1 million rows in the range
CI vs. NCI
Slide 6 -
select *
from titles
where price between $5. and $20.
Table facts:
INDEX USED PAGE READS
Clustered index
non-clustered index
25,000 +index levels
(worst case) 1,000,000,+ 7,150
No index (table scan) 50,000
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
It is feasible, occasionally likely, that a table scan is
faster than using a nonclustered index for specific
queries
The server evaluates all options at optimization time
and selects the least expensive query plan
Slide 6 - 38
CI vs. NCI
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
select title
from titles
where price between $5. and $10.
or type = 'computing'
Slide 6 -
Or Indexing
 What indexes should (could) be used?
 Will a compound index help?
 Which column(s) should be indexed?
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
 How is the following query different (from a processing standpoint)?
 What is a useful index for?
Slide 6 -
Or Indexing Continued
select title
from titles
where price between $5. and $10.
and type = 'computing'
select *
from authors
where au_fname in ('Fred', 'Sally')
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
 How many indexes may be useful?
SARG or SARG
Slide 6 - 41
Or Clauses
select *
from authors
where au_lname = 'Smith'
or au_fname = 'Fred'
select *
from authors
where au_lname in ('Smith', 'Jones', 'N/A')
Format
Examples
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Table Scan
o Each row is analyzed, and criteria applied
o Matching rows are returned in the result set
o The cost of all the index accesses is greater than the
cost of a table scan
o At least one of the clauses names a column that is not
indexed, so the only way to resolve the clause is to
perform a table scan
Slide 6 -
Or Strategy
An OR clause may be resolved via a table scan, a multiple match
index or using OR Strategy
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Multiple match index
o Using each part of the OR clause, select an index and
retrieve the row
o Only used if the results sets can not return
duplicate rows
o Rows are returned to the user as they are processed
Slide 6 -
OR Strategy Continued
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
OR Strategy (also known as dynamic index)
Used when the result from a multiple match index can
return duplicate rows
Any rowid that satisfies the OR clause is saved in a
temp table
The table is sorted
Duplicate rows are then eliminated
Results are then retrieved
Note: This strategy has additional overhead of repeated
reads and the creation and sorting of the work table
Slide 6 - 44
OR Strategy Continued
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
The server generates a dynamic index from indexes
supporting each individual SARG
The dynamic index consists of pointers to rows
matching one or both criteria
The server unions the results, removing duplicate
values
Note: If any individual SARG requires a table scan, a
table scan will resolve the query. Slide 6 - 45
OR: Example
select *
from authors
where au_lname in ('Baker', 'Garfield')
or state like 'A%'
Result
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 46
OR: Query Plan
select company, street2
from pt_sample
where id = 2017
or id = 2163
SHOWPLAN OUTPUT
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 47
OR: Query Plan
select company, street2
from pt_sample
where id = 2017
or id = 2163
SHOWPLAN OUTPUT
STEP 1
The type of query is SELECT.
2 operator(s) under root
|ROOT:EMIT Operator
|
| |RESTRICT Operator
| |
| | |SCAN Operator
| | | FROM TABLE
| | | pt_sample
| | | Table Scan.
| | | Forward Scan.
| | | Positioning at start of table.
| | | Using I/O Size 16 Kbytes for data pages.
| | | With LRU Buffer Replacement Strategy for data pages.
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
 What is the best index?
 Do the columns being selected have a bearing on
the index?
Slide 6 - 48
Index Selection and the Select List
select *
from publishers
where pub_id = 'BB1111'
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
 Should there be a difference between the utilization
of the following two indexes?
Slide 6 -
Index Selection and the Select List
create index idx1 on titles (price)
/* or */
create index idx2 on titles (price, royalty)
select royalty
from titles
where price between $10 and $20
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Composite (compound) indexes may be selected by
the server if at least the first column of the index is
specified in a where clause
Slide 6 -
Composite Indexes
create index idx1
on employee (division, department, emp_num)
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Which queries will consider using the index?
Slide 6 -
Composite Indexes (Continued)
select *
from employee
where division = 'abc',
and department = 123
and emp_num = '123-456-789'
select *
from employee
where division = 'abc'
and emp_num = '123-456-789'
select *
from employee
where department = 123
and emp_num = '123-456-789'
create index idx1
on employee (division, department, emp_num)
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Each additional index impacts update performance
In order to select appropriate indexes, we need to know
how many indexes the optimizer will use, and how many
rows are represented by the where clause
Slide 6 - 52
Composite vs. Many Indexes
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
CI or NCI on type
CI or NCI on price
One index on each of type & price
Composite on type, price
Composite on price, type
CI or NCI on type, price, pub_id, title, notes
 Which are the best options in which circumstances?
Slide 6 - 53
Composite vs. Many Indexes (Continued)
Options
select pub_id, title, notes
from titles
where type = 'Computer'
and price > $15.
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
It is imperative to be able to estimate rows returned for an index.
Therefore, the server will estimate rows returned before
index assignation
If statistics are available (When would they not be?) the server
estimates number of rows using distribution steps or index
density
If statistics are not available, the server estimates the number of
matching rows based on default statistics
o 10% for equality SARGS (=)
o 25% for closed range SARGS (between, > and <)
o 33% for open range SARGS (>, >=, <, <=)
If you have an equality join on a unique index, the server knows
only one row will match and doesn't need to use statistics
Slide 6 - 54
Index Usefulness
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Improvised SARGs are WHERE clause restrictions that are not
SARGs at compile time, but are SARGs at run time
Adaptive Server will attempt to improvise SARGs
where it can
Adaptive Server will calculate indexes for improvised SARGs as
though they were literal SARGs
Adaptive Server will use table scans for those WHERE clause
restrictions it cannot improvise into SARGs
Prior to ASE 15 COLUMN = @VARIABLE is not a SARG at compile
time, so it cannot use distribution steps, it uses index density
Consider this example: what is the potential impact of an improvised
SARG?
Slide 6 - 55
WHERE with Improvised SARGs
COLUMN like @VARIABLE
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
These are SARGS at run time, but not at
optimization time. The server will treat this as a
SARG but will use index density or default
statistics, rather than distribution steps
Slide 6 - 56
When Distribution Steps Are Not Used
Constant Expression (prior to 15)
Local Variable as Constant
Col = 5*12 Col = @value
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Selectivity is based on density stored in the statistics page
Selectivity = 1/# rows in smaller table if no statistics are available
o 1,000,000 orders, 5,000 customers
o selectivity = 1/5000
Probable number of orders/customer:
o 1,000,000 * 1/5000 = 200
Density = 1/number of unique values
o 1,000,000 rows, 1,000 unique values
o Density = 1/1,000
A single search value would, on average, yield 1,000,000 * .001
or 1000 rows
Low density is most selective; as density approaches 1, the index
approaches uselessness
Slide 6 -
Row Estimates
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
If there is no index, there will be a table scan, and the
estimate will be the number of pages in the table
(stored in sysindexes)
If there is a clustered index, estimate will be the number of
index levels plus the number of pages to scan
For a nonclustered index, estimate will be index levels +
number of leaf pages + number of qualifying rows
(which will correspond to the number of physical pages
to read)
For a unique index and an equality join, the estimate will
be 1 plus the number of index levels
Slide 6
Estimating Logical Page I/O
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
You have a 1,000,000 row table. The unique key has a
range (and random distribution) of 0 to 10,000,000
 How many rows will be returned by the following
query:
Slide 6 - 59
Data Distribution
select *
from table
where key between 1,000,000 and 2,000,000
How does the optimizer know whether to use an index or table scan?
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
 Adaptive Server keeps distribution information about indexes in
a table called sysstatistics
 There is distribution information for every index, and possibly
(depending on your DBA’s decision) statistics for nonindexed
columns as well
 The optimizer uses this information to estimate the number of
rows returned for a query
 The distribution page(s) are built at index creation time and not
maintained by the server
 The dbo should periodically issue the command to enable the
optimizer to continue picking the correct strategies
Slide 6 -
Index Statistics
update index statistics table [index]
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
With every release of the server, the optimizer gets
better at selecting optimal query paths
Forcing the optimizer to behave in a specific manner
does not allow it the freedom to change selection as
data skews
It also does not permit the optimizer to take advantage of
new strategies as advances are made in the server
software
Slide 6 - 61
When to Force Index Selection
Don't Do It!
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
When you (the developer) have information about a table
that Adaptive Server will not have at the time the query
is processed (i.e., using a temp table in a nested stored
procedure)
Occasions when you've proven the optimizer wrong
Slide 6 -
When to Force Index
Selection Continued
Exceptions
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
To force the server to use a specific index for a specific
table, you must first know the index id of the index
you want to use
In this example, the titles index with name pix will be
used for the titles table, and the publishers index
with name pix will be used for publishers
Slide 6 - 63
How to Force Index Selection
select *
from titles (index pix) join
publishers (index pix)
on titles.pub_id = publishers.pub_id
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Partition strategies
Hash partitions
List
Range
Round robins
Using alter table
Add partition
64
Partition Support Topics
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Divides large tables and indexes into manageable pieces
Are database objects that are managed independently
Create index cannot be done at partition level
Selects, inserts, deleting data can be done on partitioned table
Horizontal partitioning selects table rows that can be distributed among partitions on
different disk devices
Semantic partitioning allows data values in specified, key columns in each row to
determine the partition assignment of that row
Round-robin partitioning assigns rows randomly without reference to data values
65
Semantic Partition Support
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Hash partitioning (semantic) –system supplied hash
function determines the partition assignment for each
row
List Partitioning (semantic) compares values in key
columns to user-supplied values for each partition
Range Partitioning (semantic) –compares key columns
within a set lower and upper bound for each partition
Round-robin partitioning – randomly assigned rows to
partitions so that each partition contains equal number
of rows (default)
66
Partition Strategies
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Allows
Using the create table and create index commands when creating
partitions
Using alter table command to alter table’s partitioning strategy
Using add partition to partition to an existing table
Use of partitioning to expedite the loading of large amounts of data
67
Partition Strategies II
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Round-Robin
Parallel Inserts
Parallel Query/DBCC
Create Index
Worker Threads
Segment
Partitions
Pre – ASE 15 Partitioning  Segment
Slices
Segment partitioning
o aka 'slices'
o Table only (no index
partitioning)
Primary goals
o Decrease last page
contention
o Allow parallel query
o Allow parallel dbcc
checkstorage
o Allow parallel index creation
Assessment
o Myth that they are no longer
useful due to SAN disk
speeds
o Datarow + partitioned table
is fastest for inserts (20-
25%)
o Not a great solution
But still decent
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
ASE 15.X Semantic Partitioning
Semantic data partitioning strategies
o Hash based partitioning
o Range Partitioning
o List Partitioning
o Round-Robin Partitioning
Index partitioning
o Global indexes – Index spans all partitions
o Local indexes – Index spans one partition
Improved query support
o Optimizer and execution support
(parallelism & elimination)
Partition-aware maintenance
o Update statistics on one or all partitions
o Truncate, reorg, dbcc, bcp (out) partition
Range/Hash
Parallel Inserts
Parallel Query/DBCC
Create Index
Worker Threads
Range/Hash
Partitions
A-I J-R S-Z
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Range Partitioning - Example
create table customer
( c_custkey integer not null,
c_name varchar(20) not null,
c_address varchar(40) not null,
other columns …
) partition by range (c_custkey)
(cust_ptn1 values <= (20000) on segment1,
cust_ptn2 values <= (40000) on segment2,
cust_ptn3 values <= (60000) on segment3 )
cust_ptn3:
values <=60000
Segment 3
cust_ptn2:
values <=40000
Segment 2
cust_ptn1:
values <=20000
Segment 1
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Indexes on a partitioned table may be partitioned
o Hash, List, Range only
o Round-Robin does not support partitioned indexes
Think about it
o If partitioned, an index inherits the same partition keys as the table
Terminology
o Local Index  Index is partitioned
o Global Index  Index is not partitioned (single b-tree)
PKey Constraint is automatically partitioned
o This can lead to pkey enforcement issues if the partitioning is on columns
other than pkey
You will get a warning about this if it applies
o Work-around is to use a unique non-clustered (global) index on PKey vs.
Pkey constraint.
Index Partitioning
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Clustered (Local) Index -
ExampleCustomer is range-partitioned table on c_custkey column
Create unique clustered index ci_nkey_ckey on
customer(c_custkey, c_nationkey)
Segment 2 Segment 3Segment 1
Note: All primary key constraint indexes for range, hash, list partitioned
tables are local indexes by definition.
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
(Non-clustered) Global Index
Create unique index ci_nkey_ckey
on customer(c_nationkey,
c_custkey)
on segment4
Segment 3Segment 2Segment 1
Segment4
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
(Non-clustered) Local Index
Create unique index ci_nkey_ckey
on customer(c_nationkey, c_custkey)
on segment4 local index
Segment 1 Segment 2 Segment 3
Segment4
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Performance
Enhancement Through
Partitioned IndexIncreased concurrency through multiple index access points.
o Reduced root page contention
Index size adjusted according to the number of rows in each partition
Fewer index pages searched for smaller partitions
15.x Local Index on partitioned tablePre-15.0 with unpartitioned index
Query A
Query B
Query C
Unpartitioned Table Partitioned Table
Query A Query B Query C
Partitioned Index
Shorter Access Path
Unpartitioned Index
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Uniqueness may not be enforceable!!!
o If you partition a table by keys other than the pkey columns, duplicate
key values may be inserted
o ASE will warn you of this when you partition the table
Local Indexes vs. Unique Indexes
CACA NYNY TXTX
Partitioned Table by State (pkey is cust_id)
Insert table (cust_id, state, …)Insert table (cust_id, state, …)
values (12345,'CA', …)values (12345,'CA', …)
Insert table (cust_id, state, …)Insert table (cust_id, state, …)
values (12345,'NY', …)values (12345,'NY', …)
Insert table (cust_id, state, …)Insert table (cust_id, state, …)
values (12345,'TX', …)values (12345,'TX', …)
Local Index (Partitioned by State)
Access path
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Why does ASE Just warn vs. enforce?
o Originally table is unpartitioned with indexes 7 levels deep
o Now, partition on state
Assume 10 partitions
Assume now each index is only 3 levels deep
Unique enforcement now requires 30 (10x3) I/O's vs. 7
Unique enforcement would block partition specific maintenance
What's the Work-Around?
o Create unique/pkey indexes as nonclustered global indexes
o Other indexes can still be local – helping insert speeds.
Local Indexes vs. Unique
Indexes
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
Function-based indexes permit indexes based upon derived values in
multiple columns
Function-based indexes
Slide 6 -
create index nci on invoice_header
(substring (ID,2,9))
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
The optimizer uses indexes to improve query performance when possible
Watch out for improvised SARGs
Queries with OR may require a table scan
Try to take advantage of covered queries
Be careful when forcing an index
Partition allows large tables to be broken into usable pieces
Partition Strategies
Hash partitioning determines the partition assignment for each row
List Partitioning supplied values for each partition
Range Partitioning compares key columns within a set lower and upper bound
for each partition
Round-robin partitioning – randomly assigned rows to partitions so that each
partition contains equal number of rows (default)
Slide 6 - 79
Summary
(c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015
1. Use showplan to observe what ranges of values tend to use an index
versus a table scan to resolve this query
2. Now declare variables @low and @high and see whether variations in the
values are reflected in the optimization
3. Does it make any difference if you do this in a stored procedure?
4. Use set statistics io to track reads with various ranges, then force use of
the index / scan technique and track the query statistics. Can you
outguess the optimizer?
Slide 6 -
Lab 6.1: Indexes vs Table Scans
select max(id)
from pt_tx_NCamount
where amount between ? and ?
Annual Conference, 2015 (c) 2015 Independent SAP Technical User Group
QuestionsandAnswersQuestionsandAnswers
Annual Conference, 2015 (c) 2015 Independent SAP Technical User Group
Thank You for AttendingThank You for Attending
Pleasecompleteyour session feedbackPleasecompleteyour session feedback
formform

More Related Content

What's hot

Enhancing the Security of Data at Rest with SAP ASE 16
Enhancing the Security of Data at Rest with SAP ASE 16Enhancing the Security of Data at Rest with SAP ASE 16
Enhancing the Security of Data at Rest with SAP ASE 16SAP Technology
 
Storage Optimization and Operational Simplicity in SAP Adaptive Server Enter...
Storage Optimization and Operational Simplicity in SAP  Adaptive Server Enter...Storage Optimization and Operational Simplicity in SAP  Adaptive Server Enter...
Storage Optimization and Operational Simplicity in SAP Adaptive Server Enter...SAP Technology
 
Tabular Data Stream: The Binding Between Client and SAP ASE
Tabular Data Stream: The Binding Between Client and SAP ASETabular Data Stream: The Binding Between Client and SAP ASE
Tabular Data Stream: The Binding Between Client and SAP ASESAP Technology
 
Tips Tricks and Little known features in SAP ASE
Tips Tricks and Little known features in SAP ASETips Tricks and Little known features in SAP ASE
Tips Tricks and Little known features in SAP ASESAP Technology
 
ASE Performance and Tuning Parameters Beyond the cfg File
ASE Performance and Tuning Parameters Beyond the cfg FileASE Performance and Tuning Parameters Beyond the cfg File
ASE Performance and Tuning Parameters Beyond the cfg FileSAP Technology
 
The Science of DBMS: Data Storage & Organization
The Science of DBMS: Data Storage & Organization The Science of DBMS: Data Storage & Organization
The Science of DBMS: Data Storage & Organization SAP Technology
 
Configuring and using SIDB for ASE CE SP130
Configuring and using SIDB for ASE CE SP130Configuring and using SIDB for ASE CE SP130
Configuring and using SIDB for ASE CE SP130SAP Technology
 
Advanced ASE Performance Tuning Tips
Advanced ASE Performance Tuning Tips Advanced ASE Performance Tuning Tips
Advanced ASE Performance Tuning Tips SAP Technology
 
Tips and Tricks for SAP Sybase ASE
Tips and Tricks for SAP Sybase ASETips and Tricks for SAP Sybase ASE
Tips and Tricks for SAP Sybase ASEDon Brizendine
 
Maximizing Database Tuning in SAP SQL Anywhere
Maximizing Database Tuning in SAP SQL AnywhereMaximizing Database Tuning in SAP SQL Anywhere
Maximizing Database Tuning in SAP SQL AnywhereSAP Technology
 
What's New in SAP Replication Server 15.7.1 SP100
What's New in SAP Replication Server 15.7.1 SP100What's New in SAP Replication Server 15.7.1 SP100
What's New in SAP Replication Server 15.7.1 SP100Dobler Consulting
 
An In-Depth Look at SAP SQL Anywhere Performance Features
An In-Depth Look at SAP SQL Anywhere Performance FeaturesAn In-Depth Look at SAP SQL Anywhere Performance Features
An In-Depth Look at SAP SQL Anywhere Performance FeaturesSAP Technology
 
SQL Anywhere Tips and Tricks
SQL Anywhere Tips and TricksSQL Anywhere Tips and Tricks
SQL Anywhere Tips and TricksSAP Technology
 
Synchronizing Data in SAP HANA Using SAP SQL Anywhere
Synchronizing Data in SAP HANA Using SAP SQL AnywhereSynchronizing Data in SAP HANA Using SAP SQL Anywhere
Synchronizing Data in SAP HANA Using SAP SQL AnywhereSAP Technology
 
SAP ASE 16 SP02 Performance Features
SAP ASE 16 SP02 Performance FeaturesSAP ASE 16 SP02 Performance Features
SAP ASE 16 SP02 Performance FeaturesSAP Technology
 
SAP HANA SPS10- Predictive Analysis Library and Application Function Modeler
SAP HANA SPS10- Predictive Analysis Library and Application Function ModelerSAP HANA SPS10- Predictive Analysis Library and Application Function Modeler
SAP HANA SPS10- Predictive Analysis Library and Application Function ModelerSAP Technology
 
SAP HANA SPS1- SAP HANA Hardware Platforms
SAP HANA SPS1- SAP HANA Hardware PlatformsSAP HANA SPS1- SAP HANA Hardware Platforms
SAP HANA SPS1- SAP HANA Hardware PlatformsSAP Technology
 

What's hot (20)

Enhancing the Security of Data at Rest with SAP ASE 16
Enhancing the Security of Data at Rest with SAP ASE 16Enhancing the Security of Data at Rest with SAP ASE 16
Enhancing the Security of Data at Rest with SAP ASE 16
 
Storage Optimization and Operational Simplicity in SAP Adaptive Server Enter...
Storage Optimization and Operational Simplicity in SAP  Adaptive Server Enter...Storage Optimization and Operational Simplicity in SAP  Adaptive Server Enter...
Storage Optimization and Operational Simplicity in SAP Adaptive Server Enter...
 
Tabular Data Stream: The Binding Between Client and SAP ASE
Tabular Data Stream: The Binding Between Client and SAP ASETabular Data Stream: The Binding Between Client and SAP ASE
Tabular Data Stream: The Binding Between Client and SAP ASE
 
Tips Tricks and Little known features in SAP ASE
Tips Tricks and Little known features in SAP ASETips Tricks and Little known features in SAP ASE
Tips Tricks and Little known features in SAP ASE
 
ASE Performance and Tuning Parameters Beyond the cfg File
ASE Performance and Tuning Parameters Beyond the cfg FileASE Performance and Tuning Parameters Beyond the cfg File
ASE Performance and Tuning Parameters Beyond the cfg File
 
The Science of DBMS: Data Storage & Organization
The Science of DBMS: Data Storage & Organization The Science of DBMS: Data Storage & Organization
The Science of DBMS: Data Storage & Organization
 
Configuring and using SIDB for ASE CE SP130
Configuring and using SIDB for ASE CE SP130Configuring and using SIDB for ASE CE SP130
Configuring and using SIDB for ASE CE SP130
 
Advanced ASE Performance Tuning Tips
Advanced ASE Performance Tuning Tips Advanced ASE Performance Tuning Tips
Advanced ASE Performance Tuning Tips
 
Tips and Tricks for SAP Sybase ASE
Tips and Tricks for SAP Sybase ASETips and Tricks for SAP Sybase ASE
Tips and Tricks for SAP Sybase ASE
 
Maximizing Database Tuning in SAP SQL Anywhere
Maximizing Database Tuning in SAP SQL AnywhereMaximizing Database Tuning in SAP SQL Anywhere
Maximizing Database Tuning in SAP SQL Anywhere
 
Sap replication server
Sap replication serverSap replication server
Sap replication server
 
What's New in SAP Replication Server 15.7.1 SP100
What's New in SAP Replication Server 15.7.1 SP100What's New in SAP Replication Server 15.7.1 SP100
What's New in SAP Replication Server 15.7.1 SP100
 
An In-Depth Look at SAP SQL Anywhere Performance Features
An In-Depth Look at SAP SQL Anywhere Performance FeaturesAn In-Depth Look at SAP SQL Anywhere Performance Features
An In-Depth Look at SAP SQL Anywhere Performance Features
 
SQL Anywhere Tips and Tricks
SQL Anywhere Tips and TricksSQL Anywhere Tips and Tricks
SQL Anywhere Tips and Tricks
 
Synchronizing Data in SAP HANA Using SAP SQL Anywhere
Synchronizing Data in SAP HANA Using SAP SQL AnywhereSynchronizing Data in SAP HANA Using SAP SQL Anywhere
Synchronizing Data in SAP HANA Using SAP SQL Anywhere
 
SAP Migrations made easy
SAP Migrations made easySAP Migrations made easy
SAP Migrations made easy
 
SAP ASE 16 SP02 Performance Features
SAP ASE 16 SP02 Performance FeaturesSAP ASE 16 SP02 Performance Features
SAP ASE 16 SP02 Performance Features
 
SAP HANA SPS10- Predictive Analysis Library and Application Function Modeler
SAP HANA SPS10- Predictive Analysis Library and Application Function ModelerSAP HANA SPS10- Predictive Analysis Library and Application Function Modeler
SAP HANA SPS10- Predictive Analysis Library and Application Function Modeler
 
SAP HANA SPS1- SAP HANA Hardware Platforms
SAP HANA SPS1- SAP HANA Hardware PlatformsSAP HANA SPS1- SAP HANA Hardware Platforms
SAP HANA SPS1- SAP HANA Hardware Platforms
 
SAP Landscape 2014
SAP Landscape 2014SAP Landscape 2014
SAP Landscape 2014
 

Similar to Choosing Indexes For Performance

Sql query analyzer & maintenance
Sql query analyzer & maintenanceSql query analyzer & maintenance
Sql query analyzer & maintenancenspyrenet
 
Make streaming processing towards ANSI SQL
Make streaming processing towards ANSI SQLMake streaming processing towards ANSI SQL
Make streaming processing towards ANSI SQLDataWorks Summit
 
Analyze phase lean six sigma tollgate template
Analyze phase   lean six sigma tollgate templateAnalyze phase   lean six sigma tollgate template
Analyze phase lean six sigma tollgate templateSteven Bonacorsi
 
Analyze Phase Lean Six Sigma Tollgate Templates
Analyze Phase Lean Six Sigma Tollgate TemplatesAnalyze Phase Lean Six Sigma Tollgate Templates
Analyze Phase Lean Six Sigma Tollgate TemplatesSteven Bonacorsi
 
Lead Time Reduction in Manufacturing Process of CNC Machines by Lean Principles
Lead Time Reduction in Manufacturing Process of CNC Machines by Lean PrinciplesLead Time Reduction in Manufacturing Process of CNC Machines by Lean Principles
Lead Time Reduction in Manufacturing Process of CNC Machines by Lean PrinciplesIRJET Journal
 
Rakuten Technology Conference 2017 A Distributed SQL Database For Data Analy...
Rakuten Technology Conference 2017 A Distributed SQL Database  For Data Analy...Rakuten Technology Conference 2017 A Distributed SQL Database  For Data Analy...
Rakuten Technology Conference 2017 A Distributed SQL Database For Data Analy...Rakuten Group, Inc.
 
Starting Pack BI Open Source
Starting Pack BI Open Source Starting Pack BI Open Source
Starting Pack BI Open Source Stratebi
 
Skills Portfolio
Skills PortfolioSkills Portfolio
Skills Portfoliorolee23
 
Introduction to einstein analytics
Introduction to einstein analyticsIntroduction to einstein analytics
Introduction to einstein analyticsJan Vandevelde
 
Introduction to einstein analytics
Introduction to einstein analyticsIntroduction to einstein analytics
Introduction to einstein analyticsSteven Hugo
 
Measure phase lean six sigma tollgate template
Measure phase   lean six sigma tollgate templateMeasure phase   lean six sigma tollgate template
Measure phase lean six sigma tollgate templateSteven Bonacorsi
 
Measure phase lean six sigma tollgate template
Measure phase   lean six sigma tollgate templateMeasure phase   lean six sigma tollgate template
Measure phase lean six sigma tollgate templateSteven Bonacorsi
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performanceGuy Harrison
 
Splunk Ninjas: New features, pivot, and search dojo
Splunk Ninjas: New features, pivot, and search dojoSplunk Ninjas: New features, pivot, and search dojo
Splunk Ninjas: New features, pivot, and search dojoSplunk
 
Splunk Ninjas: New Features, Pivot, and Search Dojo
Splunk Ninjas: New Features, Pivot, and Search DojoSplunk Ninjas: New Features, Pivot, and Search Dojo
Splunk Ninjas: New Features, Pivot, and Search DojoSplunk
 
Crude-Oil Scheduling Technology: moving from simulation to optimization
Crude-Oil Scheduling Technology: moving from simulation to optimizationCrude-Oil Scheduling Technology: moving from simulation to optimization
Crude-Oil Scheduling Technology: moving from simulation to optimizationBrenno Menezes
 
Pentaho-BI
Pentaho-BIPentaho-BI
Pentaho-BIEdureka!
 
Intro of Key Features of Auto eCAAT Ent Software
Intro of Key Features of Auto eCAAT Ent SoftwareIntro of Key Features of Auto eCAAT Ent Software
Intro of Key Features of Auto eCAAT Ent Softwarerafeq
 
CAST Automated Function Points
CAST Automated Function PointsCAST Automated Function Points
CAST Automated Function PointsCAST
 

Similar to Choosing Indexes For Performance (20)

Sql query analyzer & maintenance
Sql query analyzer & maintenanceSql query analyzer & maintenance
Sql query analyzer & maintenance
 
Make streaming processing towards ANSI SQL
Make streaming processing towards ANSI SQLMake streaming processing towards ANSI SQL
Make streaming processing towards ANSI SQL
 
Analyze phase lean six sigma tollgate template
Analyze phase   lean six sigma tollgate templateAnalyze phase   lean six sigma tollgate template
Analyze phase lean six sigma tollgate template
 
Analyze Phase Lean Six Sigma Tollgate Templates
Analyze Phase Lean Six Sigma Tollgate TemplatesAnalyze Phase Lean Six Sigma Tollgate Templates
Analyze Phase Lean Six Sigma Tollgate Templates
 
Lead Time Reduction in Manufacturing Process of CNC Machines by Lean Principles
Lead Time Reduction in Manufacturing Process of CNC Machines by Lean PrinciplesLead Time Reduction in Manufacturing Process of CNC Machines by Lean Principles
Lead Time Reduction in Manufacturing Process of CNC Machines by Lean Principles
 
Rakuten Technology Conference 2017 A Distributed SQL Database For Data Analy...
Rakuten Technology Conference 2017 A Distributed SQL Database  For Data Analy...Rakuten Technology Conference 2017 A Distributed SQL Database  For Data Analy...
Rakuten Technology Conference 2017 A Distributed SQL Database For Data Analy...
 
Starting Pack BI Open Source
Starting Pack BI Open Source Starting Pack BI Open Source
Starting Pack BI Open Source
 
Skills Portfolio
Skills PortfolioSkills Portfolio
Skills Portfolio
 
Introduction to einstein analytics
Introduction to einstein analyticsIntroduction to einstein analytics
Introduction to einstein analytics
 
Introduction to einstein analytics
Introduction to einstein analyticsIntroduction to einstein analytics
Introduction to einstein analytics
 
Measure phase lean six sigma tollgate template
Measure phase   lean six sigma tollgate templateMeasure phase   lean six sigma tollgate template
Measure phase lean six sigma tollgate template
 
Measure phase lean six sigma tollgate template
Measure phase   lean six sigma tollgate templateMeasure phase   lean six sigma tollgate template
Measure phase lean six sigma tollgate template
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performance
 
Splunk Ninjas: New features, pivot, and search dojo
Splunk Ninjas: New features, pivot, and search dojoSplunk Ninjas: New features, pivot, and search dojo
Splunk Ninjas: New features, pivot, and search dojo
 
Splunk Ninjas: New Features, Pivot, and Search Dojo
Splunk Ninjas: New Features, Pivot, and Search DojoSplunk Ninjas: New Features, Pivot, and Search Dojo
Splunk Ninjas: New Features, Pivot, and Search Dojo
 
Sprint 61
Sprint 61Sprint 61
Sprint 61
 
Crude-Oil Scheduling Technology: moving from simulation to optimization
Crude-Oil Scheduling Technology: moving from simulation to optimizationCrude-Oil Scheduling Technology: moving from simulation to optimization
Crude-Oil Scheduling Technology: moving from simulation to optimization
 
Pentaho-BI
Pentaho-BIPentaho-BI
Pentaho-BI
 
Intro of Key Features of Auto eCAAT Ent Software
Intro of Key Features of Auto eCAAT Ent SoftwareIntro of Key Features of Auto eCAAT Ent Software
Intro of Key Features of Auto eCAAT Ent Software
 
CAST Automated Function Points
CAST Automated Function PointsCAST Automated Function Points
CAST Automated Function Points
 

More from SAP Technology

SAP Integration Suite L1
SAP Integration Suite L1SAP Integration Suite L1
SAP Integration Suite L1SAP Technology
 
Future-Proof Your Business Processes by Automating SAP S/4HANA processes with...
Future-Proof Your Business Processes by Automating SAP S/4HANA processes with...Future-Proof Your Business Processes by Automating SAP S/4HANA processes with...
Future-Proof Your Business Processes by Automating SAP S/4HANA processes with...SAP Technology
 
7 Top Reasons to Automate Processes with SAP Intelligent Robotic Processes Au...
7 Top Reasons to Automate Processes with SAP Intelligent Robotic Processes Au...7 Top Reasons to Automate Processes with SAP Intelligent Robotic Processes Au...
7 Top Reasons to Automate Processes with SAP Intelligent Robotic Processes Au...SAP Technology
 
Extend SAP S/4HANA to deliver real-time intelligent processes
Extend SAP S/4HANA to deliver real-time intelligent processesExtend SAP S/4HANA to deliver real-time intelligent processes
Extend SAP S/4HANA to deliver real-time intelligent processesSAP Technology
 
Process optimization and automation for SAP S/4HANA with SAP’s Business Techn...
Process optimization and automation for SAP S/4HANA with SAP’s Business Techn...Process optimization and automation for SAP S/4HANA with SAP’s Business Techn...
Process optimization and automation for SAP S/4HANA with SAP’s Business Techn...SAP Technology
 
Accelerate your journey to SAP S/4HANA with SAP’s Business Technology Platform
Accelerate your journey to SAP S/4HANA with SAP’s Business Technology PlatformAccelerate your journey to SAP S/4HANA with SAP’s Business Technology Platform
Accelerate your journey to SAP S/4HANA with SAP’s Business Technology PlatformSAP Technology
 
Accelerate Your Move to an Intelligent Enterprise with SAP Cloud Platform and...
Accelerate Your Move to an Intelligent Enterprise with SAP Cloud Platform and...Accelerate Your Move to an Intelligent Enterprise with SAP Cloud Platform and...
Accelerate Your Move to an Intelligent Enterprise with SAP Cloud Platform and...SAP Technology
 
Transform your business with intelligent insights and SAP S/4HANA
Transform your business with intelligent insights and SAP S/4HANATransform your business with intelligent insights and SAP S/4HANA
Transform your business with intelligent insights and SAP S/4HANASAP Technology
 
SAP Cloud Platform for SAP S/4HANA: Accelerate your move to an Intelligent En...
SAP Cloud Platform for SAP S/4HANA: Accelerate your move to an Intelligent En...SAP Cloud Platform for SAP S/4HANA: Accelerate your move to an Intelligent En...
SAP Cloud Platform for SAP S/4HANA: Accelerate your move to an Intelligent En...SAP Technology
 
Innovate collaborative applications with SAP Jam Collaboration & SAP Cloud Pl...
Innovate collaborative applications with SAP Jam Collaboration & SAP Cloud Pl...Innovate collaborative applications with SAP Jam Collaboration & SAP Cloud Pl...
Innovate collaborative applications with SAP Jam Collaboration & SAP Cloud Pl...SAP Technology
 
The IoT Imperative for Consumer Products
The IoT Imperative for Consumer ProductsThe IoT Imperative for Consumer Products
The IoT Imperative for Consumer ProductsSAP Technology
 
The IoT Imperative for Discrete Manufacturers - Automotive, Aerospace & Defen...
The IoT Imperative for Discrete Manufacturers - Automotive, Aerospace & Defen...The IoT Imperative for Discrete Manufacturers - Automotive, Aerospace & Defen...
The IoT Imperative for Discrete Manufacturers - Automotive, Aerospace & Defen...SAP Technology
 
IoT is Enabling a New Era of Shareholder Value in Energy and Natural Resource...
IoT is Enabling a New Era of Shareholder Value in Energy and Natural Resource...IoT is Enabling a New Era of Shareholder Value in Energy and Natural Resource...
IoT is Enabling a New Era of Shareholder Value in Energy and Natural Resource...SAP Technology
 
The IoT Imperative in Government and Healthcare
The IoT Imperative in Government and HealthcareThe IoT Imperative in Government and Healthcare
The IoT Imperative in Government and HealthcareSAP Technology
 
SAP S/4HANA Finance and the Digital Core
SAP S/4HANA Finance and the Digital CoreSAP S/4HANA Finance and the Digital Core
SAP S/4HANA Finance and the Digital CoreSAP Technology
 
Five Reasons To Skip SAP Suite on HANA and Go Directly to SAP S/4HANA
Five Reasons To Skip SAP Suite on HANA and Go Directly to SAP S/4HANAFive Reasons To Skip SAP Suite on HANA and Go Directly to SAP S/4HANA
Five Reasons To Skip SAP Suite on HANA and Go Directly to SAP S/4HANASAP Technology
 
SAP Helps Reduce Silos Between Business and Spatial Data
SAP Helps Reduce Silos Between Business and Spatial DataSAP Helps Reduce Silos Between Business and Spatial Data
SAP Helps Reduce Silos Between Business and Spatial DataSAP Technology
 
Spotlight on Financial Services with Calypso and SAP ASE
Spotlight on Financial Services with Calypso and SAP ASESpotlight on Financial Services with Calypso and SAP ASE
Spotlight on Financial Services with Calypso and SAP ASESAP Technology
 
Spark Usage in Enterprise Business Operations
Spark Usage in Enterprise Business OperationsSpark Usage in Enterprise Business Operations
Spark Usage in Enterprise Business OperationsSAP Technology
 

More from SAP Technology (20)

SAP Integration Suite L1
SAP Integration Suite L1SAP Integration Suite L1
SAP Integration Suite L1
 
Future-Proof Your Business Processes by Automating SAP S/4HANA processes with...
Future-Proof Your Business Processes by Automating SAP S/4HANA processes with...Future-Proof Your Business Processes by Automating SAP S/4HANA processes with...
Future-Proof Your Business Processes by Automating SAP S/4HANA processes with...
 
7 Top Reasons to Automate Processes with SAP Intelligent Robotic Processes Au...
7 Top Reasons to Automate Processes with SAP Intelligent Robotic Processes Au...7 Top Reasons to Automate Processes with SAP Intelligent Robotic Processes Au...
7 Top Reasons to Automate Processes with SAP Intelligent Robotic Processes Au...
 
Extend SAP S/4HANA to deliver real-time intelligent processes
Extend SAP S/4HANA to deliver real-time intelligent processesExtend SAP S/4HANA to deliver real-time intelligent processes
Extend SAP S/4HANA to deliver real-time intelligent processes
 
Process optimization and automation for SAP S/4HANA with SAP’s Business Techn...
Process optimization and automation for SAP S/4HANA with SAP’s Business Techn...Process optimization and automation for SAP S/4HANA with SAP’s Business Techn...
Process optimization and automation for SAP S/4HANA with SAP’s Business Techn...
 
Accelerate your journey to SAP S/4HANA with SAP’s Business Technology Platform
Accelerate your journey to SAP S/4HANA with SAP’s Business Technology PlatformAccelerate your journey to SAP S/4HANA with SAP’s Business Technology Platform
Accelerate your journey to SAP S/4HANA with SAP’s Business Technology Platform
 
Accelerate Your Move to an Intelligent Enterprise with SAP Cloud Platform and...
Accelerate Your Move to an Intelligent Enterprise with SAP Cloud Platform and...Accelerate Your Move to an Intelligent Enterprise with SAP Cloud Platform and...
Accelerate Your Move to an Intelligent Enterprise with SAP Cloud Platform and...
 
Transform your business with intelligent insights and SAP S/4HANA
Transform your business with intelligent insights and SAP S/4HANATransform your business with intelligent insights and SAP S/4HANA
Transform your business with intelligent insights and SAP S/4HANA
 
SAP Cloud Platform for SAP S/4HANA: Accelerate your move to an Intelligent En...
SAP Cloud Platform for SAP S/4HANA: Accelerate your move to an Intelligent En...SAP Cloud Platform for SAP S/4HANA: Accelerate your move to an Intelligent En...
SAP Cloud Platform for SAP S/4HANA: Accelerate your move to an Intelligent En...
 
Innovate collaborative applications with SAP Jam Collaboration & SAP Cloud Pl...
Innovate collaborative applications with SAP Jam Collaboration & SAP Cloud Pl...Innovate collaborative applications with SAP Jam Collaboration & SAP Cloud Pl...
Innovate collaborative applications with SAP Jam Collaboration & SAP Cloud Pl...
 
The IoT Imperative for Consumer Products
The IoT Imperative for Consumer ProductsThe IoT Imperative for Consumer Products
The IoT Imperative for Consumer Products
 
The IoT Imperative for Discrete Manufacturers - Automotive, Aerospace & Defen...
The IoT Imperative for Discrete Manufacturers - Automotive, Aerospace & Defen...The IoT Imperative for Discrete Manufacturers - Automotive, Aerospace & Defen...
The IoT Imperative for Discrete Manufacturers - Automotive, Aerospace & Defen...
 
IoT is Enabling a New Era of Shareholder Value in Energy and Natural Resource...
IoT is Enabling a New Era of Shareholder Value in Energy and Natural Resource...IoT is Enabling a New Era of Shareholder Value in Energy and Natural Resource...
IoT is Enabling a New Era of Shareholder Value in Energy and Natural Resource...
 
The IoT Imperative in Government and Healthcare
The IoT Imperative in Government and HealthcareThe IoT Imperative in Government and Healthcare
The IoT Imperative in Government and Healthcare
 
SAP S/4HANA Finance and the Digital Core
SAP S/4HANA Finance and the Digital CoreSAP S/4HANA Finance and the Digital Core
SAP S/4HANA Finance and the Digital Core
 
Five Reasons To Skip SAP Suite on HANA and Go Directly to SAP S/4HANA
Five Reasons To Skip SAP Suite on HANA and Go Directly to SAP S/4HANAFive Reasons To Skip SAP Suite on HANA and Go Directly to SAP S/4HANA
Five Reasons To Skip SAP Suite on HANA and Go Directly to SAP S/4HANA
 
SAP Helps Reduce Silos Between Business and Spatial Data
SAP Helps Reduce Silos Between Business and Spatial DataSAP Helps Reduce Silos Between Business and Spatial Data
SAP Helps Reduce Silos Between Business and Spatial Data
 
Why SAP HANA?
Why SAP HANA?Why SAP HANA?
Why SAP HANA?
 
Spotlight on Financial Services with Calypso and SAP ASE
Spotlight on Financial Services with Calypso and SAP ASESpotlight on Financial Services with Calypso and SAP ASE
Spotlight on Financial Services with Calypso and SAP ASE
 
Spark Usage in Enterprise Business Operations
Spark Usage in Enterprise Business OperationsSpark Usage in Enterprise Business Operations
Spark Usage in Enterprise Business Operations
 

Choosing Indexes For Performance

  • 1. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 ISUG-TECH 2015 ConferenceISUG-TECH 2015 Conference Pr esent er ’ s Sessi on Ti t l e her ePr esent er ’ s Sessi on Ti t l e her e Pr esent er ’ s namePr esent er ’ s name
  • 2. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 AgendaAgenda Welcome Speaker Introduction Session Title (add presentation title) Q&A
  • 3. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Jeff GarbusJeff Garbus Speaker(s) should add a few introductory commentsabout him/herself
  • 4. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Single – Table Optimization
  • 5. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Acknowledgements Sybase Adaptive Server is a trademark of Sybase Inc. This presentation is copyrighted. This presentation is not for re- sale This presentation shall not be used or modified without express written consent of Soaring Eagle Consulting, Inc. Slide 6 - 5
  • 6. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Examine detailed topics in query optimization Indexes with SARGs Improvised SARGs Clustered vs. nonclustered Indexes Queries with OR Index covering Forcing index selection Partition support Slide 6 - Single - Table Optimization Topics
  • 7. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Table scans Index searches Covered index searches Slide 6 - 7 Adaptive Server Search Techniques ASE uses three basic search techniques for query resolution
  • 8. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Scans are expensive Table scans may be planned even if the rest of the query is false! Slide 6 - 8 Table Scans If Adaptive Server can’t resolve a query any other way, it does a table scan Identify table scan searches select * from pt_tx where 1 = 2
  • 9. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 9 Table Scans select * from pt_tx where 1=2 SHOWPLAN OUTPUT
  • 10. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 10 Table Scans Continued SHOWPLAN OUTPUT QUERY PLAN FOR STATEMENT 1 (at line 1). STEP 1 The type of query is SELECT. 2 operator(s) under root |ROOT:EMIT Operator | | |RESTRICT Operator | | | | |SCAN Operator | | | FROM TABLE | | | pt_tx | | | Table Scan. | | | Forward Scan. | | | Positioning at start of table. | | | Using I/O Size 16 Kbytes for data pages. | | | With LRU Buffer Replacement Strategy for data pages. select * from pt_tx where 1=2
  • 11. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 11 Table Scans DBCC TRACEON (3604, 302, select * from pt_tx where 1=2
  • 12. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 12 Table Scan Output: SELECT select * from pt_tx SHOWPLAN
  • 13. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 13 Table Scan Output: SELECT select * from pt_tx SHOWPLAN STEP 1 The type of query is SELECT. 1 operator(s) under root |ROOT:EMIT Operator | | |SCAN Operator | | FROM TABLE | | pt_tx | | Table Scan. | | Forward Scan. | | Positioning at start of table. | | Using I/O Size 16 Kbytes for data pages. | | With LRU Buffer Replacement Strategy for data pages.
  • 14. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 14 Table Scan Output: UPDATE update pt_tx set id = id + 1 SHOWPLAN OUTPUT
  • 15. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 15 Table Scan Output: UPDATE update pt_tx set id = id + 1 SHOWPLAN OUTPUT STEP 1 The type of query is UPDATE. 2 operator(s) under root |ROOT:EMIT Operator | | |UPDATE Operator | | The update mode is direct. | | | | |SCAN Operator | | | FROM TABLE | | | pt_tx | | | Table Scan. | | | Forward Scan. | | | Positioning at start of table. | | | Using I/O Size 16 Kbytes for data pages. | | | With LRU Buffer Replacement Strategy for data pages. | | | | TO TABLE | | pt_tx | | Using I/O Size 2 Kbytes for data pages.
  • 16. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Use SET STATISTICS IO ON to verify what actually happens when the query executes Slide 6 - 16 Optimization vs. Execution Scans planned at optimization may not happen update pt_tx set id = id + 1 Example 1 (scan planned and executed)
  • 17. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 STATISTICS IO OUTPUT Slide 6 - 17 Optimization vs. Execution Slide 2 of 5 update pt_tx set id = id + 1
  • 18. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 STEP 1 The type of query is UPDATE. 2 operator(s) under root |ROOT:EMIT Operator | | |UPDATE Operator | | The update mode is direct. | | | | |SCAN Operator | | | FROM TABLE | | | pt_tx | | | Table Scan. | | | Forward Scan. | | | Positioning at start of table. | | | Using I/O Size 16 Kbytes for data pages. | | | With LRU Buffer Replacement Strategy for data pages. | | | | TO TABLE | | pt_tx | | Using I/O Size 2 Kbytes for data pages. STATISTICS IO OUTPUT Slide 6 - 18 Optimization vs. Execution update pt_tx set id = id + 1 Table: pt_tx scan count 1, logical reads: (regular=6 apf=0 total=6), physical reads: (regular=0 apf=0 total=0), apf IOs used=0 Table: pt_tx scan count 0, logical reads: (regular=0 apf=0 total=0), physical reads: (regular=0 apf=0 total=0), apf IOs used=0 Total writes for this command: 9
  • 19. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 19 Optimization vs. Execution update pt_tx set id = id + 1 where 1 = 2 SHOWPLAN Example 2 (scan planned but not executed)
  • 20. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 STEP 1 The type of query is UPDATE. 2 operator(s) under root |ROOT:EMIT Operator | | |UPDATE Operator | | The update mode is direct. | | | | |SCAN Operator | | | FROM TABLE | | | pt_tx | | | Table Scan. | | | Forward Scan. | | | Positioning at start of table. | | | Using I/O Size 16 Kbytes for data pages. | | | With LRU Buffer Replacement Strategy for data pages. | | | | TO TABLE | | pt_tx | | Using I/O Size 2 Kbytes for data pages. Slide 6 - 20 Optimization vs. Execution update pt_tx set id = id + 1 where 1 = 2 SHOWPLAN Example 2 (scan planned but not executed)
  • 21. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 In this example, the optimizer still plans a table scan even though the WHERE clause short-circuits the query at execution time Use STATISTICS IO output to verify a scan really happened Slide 6 - 21 Optimization vs. Execution Continued STATISTICS Table: pt_tx scan count 1, logical reads: (regular=6 apf=0 total=6), physical reads: (regular=0 apf=0 total=0), apf IOs used=0 Table: pt_tx scan count 0, logical reads: (regular=0 apf=0 total=0), physical reads: (regular=0 apf=0 total=0), apf IOs used=0 Total writes for this command: 9
  • 22. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015  Index types  Optimizer selection criteria  When indexes slow access  Index statistics and usage Slide 6 - 22 Index Selection Topics
  • 23. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 ASE provides three types of indexes Clustered Nonclustered Full text One clustered index per table Data is maintained in clustered index order 248 nonclustered indexes per table Nonclustered indexes maintain pointers to rows Full text indexing is beyond scope Slide 6 - 23 Index Types
  • 24. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Indexes are balanced b-tree structures An index may contain between 1 and 31 columns, but the total index entry width must be no greater than 600 bytes Text, image and bit columns can be indexed Indexes are maintained and used internally by the server to improve performance or to enforce uniqueness The application programmer does not usually refer to indexes Slide 6 - 24 Index Types
  • 25. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Here, we’re clustered on last name With a clustered index, there will be one entry on the last intermediate index level page for each data page The data page is the leaf or bottom level of the index Slide 6 - 25 Clustered Index Mechanism Houston Exeter Brown Albert Quincy Mason Jones Albert Loon Klein Jude Jones Paul Parker Neenan Mason Alexis, Amy, ... Root Page Intermediate Page Data Page Amundsen, Fred, ... Baker, Joe, ... Best, Elizabeth, ... Albert, John, ... Masonelli, Irving, ... Narin, Mabelle, ... Naselle, Juan, ... Neat, Juanita Mason, Emma, ... ... ... ...
  • 26. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015  Here, we have a nonclustered index on first name  The nonclustered index has an extra, leaf level for page / row pointers  Nonclustered indexes do not affect data placement Slide 6 - 26 Nonclustered Index Mechanism Dave Bob Amy Zelda Elizabeth Elizabeth George George Amy ... ... ... ... ... ... Sam Sam Alexis, Amy, ... Root Page Intermediate Page Data Page Amundsen, Fred, ... Baker, Joe, ... Best, Elizabeth, ... Albert, John, ... Masonelli, Irving, ... Narin, Anabelle, ... Naselle, Amy, ... Neat, Juanita Mason, Emma, ... Zelda ... ... ... Amy Amy ... ... Emma ... Leaf Page Anabelle ...
  • 27. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 A clustered index tends to be 1 I/O faster than a nonclustered index for a single-row lookup Clustered indexes are excellent for retrieving ranges of data Clustered indexes are excellent for queries with order by Nonclustered indexes are a bit slower, take up much more disk space, but are usually the next best alternative to a table scan Nonclustered indexes may cover the query for maximal retrieval speed; For some queries; covered queries, nonclustered indexes can be faster Slide 6 - 27 Clustered vs. Nonclustered
  • 28. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 A primary key is a logical concept, not a physical concept Indexes are physical concepts, not logical concepts There is a strong correlation between the logical concept of a key and the physical concept of an index By default, when you define relationships as part of table design, you will build indexes to support the joins / lookups By default, when you define a primary key, you will create a unique clustered index on the table Unique is good, clustered isn’t always good Primary Key vs. Clustered vs. Nonclustered Page 6 - 28
  • 29. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 During the index selection phase of optimization the optimizer decides which (if any) indexes best resolve the query o Identify which indexes match the where clauses o Estimate rows to be returned o Estimate page reads Slide 6 - 29 Optimizer Selection Criteria
  • 30. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015  Indexes must correspond with SARGs.  Useful indexes will specify a row or rows or set bounds for the result set  An index may be used if at least the first column of the index matches the SARG where dob between '3/3/1941' and '4/4/65' Slide 6 - 30 SARG Matching
  • 31. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Which of the following queries (if any) is helped by the index? select * from authors where au_fname = 'Jim' and au_lname = 'Smith‘ select * from authors where au_fname = 'Jim‘ select * from authors where au_lname = 'Smith' or au_fname = 'Jim' Slide 6 - 31 SARG Matching (Continued) Create index a on authors(au_lname, au_fname)
  • 32. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Columns searched by range of values Columns by which the data is frequently sorted (order by or group by) Sequentially accessed columns Join columns (if other than the primary key) Static columns Slide 6 - 32 Using Indexes Clustered Index Indications
  • 33. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 NCI selection tends to be much more effective if less than about 10% of the data is to be accessed (documentation says 20%, it is wrong) NCIs help sorts, joins, group by clauses, etc., if other column(s) must be used for the CI Index covering Slide 6 - 33 Using Indexes Nonclustered Index
  • 34. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 The server can use the leaf level of a nonclustered index the way it usually reads the data pages of a table: this is index covering. The server can skip reading data pages The server can walk leaf page pointers A nonclustered index will be faster than a clustered index if the index covers the query for a range of data (why?) Adding columns to nonclustered indexes is a common method of reducing query time This has particular benefits with aggregates Slide 6 - 34 Index Covering
  • 35. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Beware making the index too wide; As index width approaches row width, the benefit of covering is reduced # of levels in the index increases Index scan time approaches table scan time Remember that changes to data will cascade into indexes Over-indexing can cause OLTP performance problems Slide 6 - 35 Index Covering Continued
  • 36. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015  What index will optimize this query?  What index will optimize this query?  In the second query, what would the net effect be of changing the range to this? select title from titles where title = 'Future Shock' Slide 6 - 36 Index Selection Examples select title from titles where price between $5. and $20. between $500 and $600
  • 37. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 2,000,000 titles 40 rows / page (=50,000 pages) 1 million rows in the range CI vs. NCI Slide 6 - select * from titles where price between $5. and $20. Table facts: INDEX USED PAGE READS Clustered index non-clustered index 25,000 +index levels (worst case) 1,000,000,+ 7,150 No index (table scan) 50,000
  • 38. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 It is feasible, occasionally likely, that a table scan is faster than using a nonclustered index for specific queries The server evaluates all options at optimization time and selects the least expensive query plan Slide 6 - 38 CI vs. NCI
  • 39. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 select title from titles where price between $5. and $10. or type = 'computing' Slide 6 - Or Indexing  What indexes should (could) be used?  Will a compound index help?  Which column(s) should be indexed?
  • 40. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015  How is the following query different (from a processing standpoint)?  What is a useful index for? Slide 6 - Or Indexing Continued select title from titles where price between $5. and $10. and type = 'computing' select * from authors where au_fname in ('Fred', 'Sally')
  • 41. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015  How many indexes may be useful? SARG or SARG Slide 6 - 41 Or Clauses select * from authors where au_lname = 'Smith' or au_fname = 'Fred' select * from authors where au_lname in ('Smith', 'Jones', 'N/A') Format Examples
  • 42. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Table Scan o Each row is analyzed, and criteria applied o Matching rows are returned in the result set o The cost of all the index accesses is greater than the cost of a table scan o At least one of the clauses names a column that is not indexed, so the only way to resolve the clause is to perform a table scan Slide 6 - Or Strategy An OR clause may be resolved via a table scan, a multiple match index or using OR Strategy
  • 43. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Multiple match index o Using each part of the OR clause, select an index and retrieve the row o Only used if the results sets can not return duplicate rows o Rows are returned to the user as they are processed Slide 6 - OR Strategy Continued
  • 44. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 OR Strategy (also known as dynamic index) Used when the result from a multiple match index can return duplicate rows Any rowid that satisfies the OR clause is saved in a temp table The table is sorted Duplicate rows are then eliminated Results are then retrieved Note: This strategy has additional overhead of repeated reads and the creation and sorting of the work table Slide 6 - 44 OR Strategy Continued
  • 45. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 The server generates a dynamic index from indexes supporting each individual SARG The dynamic index consists of pointers to rows matching one or both criteria The server unions the results, removing duplicate values Note: If any individual SARG requires a table scan, a table scan will resolve the query. Slide 6 - 45 OR: Example select * from authors where au_lname in ('Baker', 'Garfield') or state like 'A%' Result
  • 46. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 46 OR: Query Plan select company, street2 from pt_sample where id = 2017 or id = 2163 SHOWPLAN OUTPUT
  • 47. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Slide 6 - 47 OR: Query Plan select company, street2 from pt_sample where id = 2017 or id = 2163 SHOWPLAN OUTPUT STEP 1 The type of query is SELECT. 2 operator(s) under root |ROOT:EMIT Operator | | |RESTRICT Operator | | | | |SCAN Operator | | | FROM TABLE | | | pt_sample | | | Table Scan. | | | Forward Scan. | | | Positioning at start of table. | | | Using I/O Size 16 Kbytes for data pages. | | | With LRU Buffer Replacement Strategy for data pages.
  • 48. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015  What is the best index?  Do the columns being selected have a bearing on the index? Slide 6 - 48 Index Selection and the Select List select * from publishers where pub_id = 'BB1111'
  • 49. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015  Should there be a difference between the utilization of the following two indexes? Slide 6 - Index Selection and the Select List create index idx1 on titles (price) /* or */ create index idx2 on titles (price, royalty) select royalty from titles where price between $10 and $20
  • 50. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Composite (compound) indexes may be selected by the server if at least the first column of the index is specified in a where clause Slide 6 - Composite Indexes create index idx1 on employee (division, department, emp_num)
  • 51. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Which queries will consider using the index? Slide 6 - Composite Indexes (Continued) select * from employee where division = 'abc', and department = 123 and emp_num = '123-456-789' select * from employee where division = 'abc' and emp_num = '123-456-789' select * from employee where department = 123 and emp_num = '123-456-789' create index idx1 on employee (division, department, emp_num)
  • 52. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Each additional index impacts update performance In order to select appropriate indexes, we need to know how many indexes the optimizer will use, and how many rows are represented by the where clause Slide 6 - 52 Composite vs. Many Indexes
  • 53. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 CI or NCI on type CI or NCI on price One index on each of type & price Composite on type, price Composite on price, type CI or NCI on type, price, pub_id, title, notes  Which are the best options in which circumstances? Slide 6 - 53 Composite vs. Many Indexes (Continued) Options select pub_id, title, notes from titles where type = 'Computer' and price > $15.
  • 54. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 It is imperative to be able to estimate rows returned for an index. Therefore, the server will estimate rows returned before index assignation If statistics are available (When would they not be?) the server estimates number of rows using distribution steps or index density If statistics are not available, the server estimates the number of matching rows based on default statistics o 10% for equality SARGS (=) o 25% for closed range SARGS (between, > and <) o 33% for open range SARGS (>, >=, <, <=) If you have an equality join on a unique index, the server knows only one row will match and doesn't need to use statistics Slide 6 - 54 Index Usefulness
  • 55. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Improvised SARGs are WHERE clause restrictions that are not SARGs at compile time, but are SARGs at run time Adaptive Server will attempt to improvise SARGs where it can Adaptive Server will calculate indexes for improvised SARGs as though they were literal SARGs Adaptive Server will use table scans for those WHERE clause restrictions it cannot improvise into SARGs Prior to ASE 15 COLUMN = @VARIABLE is not a SARG at compile time, so it cannot use distribution steps, it uses index density Consider this example: what is the potential impact of an improvised SARG? Slide 6 - 55 WHERE with Improvised SARGs COLUMN like @VARIABLE
  • 56. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 These are SARGS at run time, but not at optimization time. The server will treat this as a SARG but will use index density or default statistics, rather than distribution steps Slide 6 - 56 When Distribution Steps Are Not Used Constant Expression (prior to 15) Local Variable as Constant Col = 5*12 Col = @value
  • 57. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Selectivity is based on density stored in the statistics page Selectivity = 1/# rows in smaller table if no statistics are available o 1,000,000 orders, 5,000 customers o selectivity = 1/5000 Probable number of orders/customer: o 1,000,000 * 1/5000 = 200 Density = 1/number of unique values o 1,000,000 rows, 1,000 unique values o Density = 1/1,000 A single search value would, on average, yield 1,000,000 * .001 or 1000 rows Low density is most selective; as density approaches 1, the index approaches uselessness Slide 6 - Row Estimates
  • 58. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 If there is no index, there will be a table scan, and the estimate will be the number of pages in the table (stored in sysindexes) If there is a clustered index, estimate will be the number of index levels plus the number of pages to scan For a nonclustered index, estimate will be index levels + number of leaf pages + number of qualifying rows (which will correspond to the number of physical pages to read) For a unique index and an equality join, the estimate will be 1 plus the number of index levels Slide 6 Estimating Logical Page I/O
  • 59. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 You have a 1,000,000 row table. The unique key has a range (and random distribution) of 0 to 10,000,000  How many rows will be returned by the following query: Slide 6 - 59 Data Distribution select * from table where key between 1,000,000 and 2,000,000 How does the optimizer know whether to use an index or table scan?
  • 60. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015  Adaptive Server keeps distribution information about indexes in a table called sysstatistics  There is distribution information for every index, and possibly (depending on your DBA’s decision) statistics for nonindexed columns as well  The optimizer uses this information to estimate the number of rows returned for a query  The distribution page(s) are built at index creation time and not maintained by the server  The dbo should periodically issue the command to enable the optimizer to continue picking the correct strategies Slide 6 - Index Statistics update index statistics table [index]
  • 61. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 With every release of the server, the optimizer gets better at selecting optimal query paths Forcing the optimizer to behave in a specific manner does not allow it the freedom to change selection as data skews It also does not permit the optimizer to take advantage of new strategies as advances are made in the server software Slide 6 - 61 When to Force Index Selection Don't Do It!
  • 62. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 When you (the developer) have information about a table that Adaptive Server will not have at the time the query is processed (i.e., using a temp table in a nested stored procedure) Occasions when you've proven the optimizer wrong Slide 6 - When to Force Index Selection Continued Exceptions
  • 63. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 To force the server to use a specific index for a specific table, you must first know the index id of the index you want to use In this example, the titles index with name pix will be used for the titles table, and the publishers index with name pix will be used for publishers Slide 6 - 63 How to Force Index Selection select * from titles (index pix) join publishers (index pix) on titles.pub_id = publishers.pub_id
  • 64. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Partition strategies Hash partitions List Range Round robins Using alter table Add partition 64 Partition Support Topics
  • 65. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Divides large tables and indexes into manageable pieces Are database objects that are managed independently Create index cannot be done at partition level Selects, inserts, deleting data can be done on partitioned table Horizontal partitioning selects table rows that can be distributed among partitions on different disk devices Semantic partitioning allows data values in specified, key columns in each row to determine the partition assignment of that row Round-robin partitioning assigns rows randomly without reference to data values 65 Semantic Partition Support
  • 66. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Hash partitioning (semantic) –system supplied hash function determines the partition assignment for each row List Partitioning (semantic) compares values in key columns to user-supplied values for each partition Range Partitioning (semantic) –compares key columns within a set lower and upper bound for each partition Round-robin partitioning – randomly assigned rows to partitions so that each partition contains equal number of rows (default) 66 Partition Strategies
  • 67. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Allows Using the create table and create index commands when creating partitions Using alter table command to alter table’s partitioning strategy Using add partition to partition to an existing table Use of partitioning to expedite the loading of large amounts of data 67 Partition Strategies II
  • 68. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Round-Robin Parallel Inserts Parallel Query/DBCC Create Index Worker Threads Segment Partitions Pre – ASE 15 Partitioning  Segment Slices Segment partitioning o aka 'slices' o Table only (no index partitioning) Primary goals o Decrease last page contention o Allow parallel query o Allow parallel dbcc checkstorage o Allow parallel index creation Assessment o Myth that they are no longer useful due to SAN disk speeds o Datarow + partitioned table is fastest for inserts (20- 25%) o Not a great solution But still decent
  • 69. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 ASE 15.X Semantic Partitioning Semantic data partitioning strategies o Hash based partitioning o Range Partitioning o List Partitioning o Round-Robin Partitioning Index partitioning o Global indexes – Index spans all partitions o Local indexes – Index spans one partition Improved query support o Optimizer and execution support (parallelism & elimination) Partition-aware maintenance o Update statistics on one or all partitions o Truncate, reorg, dbcc, bcp (out) partition Range/Hash Parallel Inserts Parallel Query/DBCC Create Index Worker Threads Range/Hash Partitions A-I J-R S-Z
  • 70. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Range Partitioning - Example create table customer ( c_custkey integer not null, c_name varchar(20) not null, c_address varchar(40) not null, other columns … ) partition by range (c_custkey) (cust_ptn1 values <= (20000) on segment1, cust_ptn2 values <= (40000) on segment2, cust_ptn3 values <= (60000) on segment3 ) cust_ptn3: values <=60000 Segment 3 cust_ptn2: values <=40000 Segment 2 cust_ptn1: values <=20000 Segment 1
  • 71. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Indexes on a partitioned table may be partitioned o Hash, List, Range only o Round-Robin does not support partitioned indexes Think about it o If partitioned, an index inherits the same partition keys as the table Terminology o Local Index  Index is partitioned o Global Index  Index is not partitioned (single b-tree) PKey Constraint is automatically partitioned o This can lead to pkey enforcement issues if the partitioning is on columns other than pkey You will get a warning about this if it applies o Work-around is to use a unique non-clustered (global) index on PKey vs. Pkey constraint. Index Partitioning
  • 72. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Clustered (Local) Index - ExampleCustomer is range-partitioned table on c_custkey column Create unique clustered index ci_nkey_ckey on customer(c_custkey, c_nationkey) Segment 2 Segment 3Segment 1 Note: All primary key constraint indexes for range, hash, list partitioned tables are local indexes by definition.
  • 73. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 (Non-clustered) Global Index Create unique index ci_nkey_ckey on customer(c_nationkey, c_custkey) on segment4 Segment 3Segment 2Segment 1 Segment4
  • 74. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 (Non-clustered) Local Index Create unique index ci_nkey_ckey on customer(c_nationkey, c_custkey) on segment4 local index Segment 1 Segment 2 Segment 3 Segment4
  • 75. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Performance Enhancement Through Partitioned IndexIncreased concurrency through multiple index access points. o Reduced root page contention Index size adjusted according to the number of rows in each partition Fewer index pages searched for smaller partitions 15.x Local Index on partitioned tablePre-15.0 with unpartitioned index Query A Query B Query C Unpartitioned Table Partitioned Table Query A Query B Query C Partitioned Index Shorter Access Path Unpartitioned Index
  • 76. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Uniqueness may not be enforceable!!! o If you partition a table by keys other than the pkey columns, duplicate key values may be inserted o ASE will warn you of this when you partition the table Local Indexes vs. Unique Indexes CACA NYNY TXTX Partitioned Table by State (pkey is cust_id) Insert table (cust_id, state, …)Insert table (cust_id, state, …) values (12345,'CA', …)values (12345,'CA', …) Insert table (cust_id, state, …)Insert table (cust_id, state, …) values (12345,'NY', …)values (12345,'NY', …) Insert table (cust_id, state, …)Insert table (cust_id, state, …) values (12345,'TX', …)values (12345,'TX', …) Local Index (Partitioned by State) Access path
  • 77. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Why does ASE Just warn vs. enforce? o Originally table is unpartitioned with indexes 7 levels deep o Now, partition on state Assume 10 partitions Assume now each index is only 3 levels deep Unique enforcement now requires 30 (10x3) I/O's vs. 7 Unique enforcement would block partition specific maintenance What's the Work-Around? o Create unique/pkey indexes as nonclustered global indexes o Other indexes can still be local – helping insert speeds. Local Indexes vs. Unique Indexes
  • 78. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 Function-based indexes permit indexes based upon derived values in multiple columns Function-based indexes Slide 6 - create index nci on invoice_header (substring (ID,2,9))
  • 79. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 The optimizer uses indexes to improve query performance when possible Watch out for improvised SARGs Queries with OR may require a table scan Try to take advantage of covered queries Be careful when forcing an index Partition allows large tables to be broken into usable pieces Partition Strategies Hash partitioning determines the partition assignment for each row List Partitioning supplied values for each partition Range Partitioning compares key columns within a set lower and upper bound for each partition Round-robin partitioning – randomly assigned rows to partitions so that each partition contains equal number of rows (default) Slide 6 - 79 Summary
  • 80. (c) 2015 Independent SAP Technical User GroupAnnual Conference, 2015 1. Use showplan to observe what ranges of values tend to use an index versus a table scan to resolve this query 2. Now declare variables @low and @high and see whether variations in the values are reflected in the optimization 3. Does it make any difference if you do this in a stored procedure? 4. Use set statistics io to track reads with various ranges, then force use of the index / scan technique and track the query statistics. Can you outguess the optimizer? Slide 6 - Lab 6.1: Indexes vs Table Scans select max(id) from pt_tx_NCamount where amount between ? and ?
  • 81. Annual Conference, 2015 (c) 2015 Independent SAP Technical User Group QuestionsandAnswersQuestionsandAnswers
  • 82. Annual Conference, 2015 (c) 2015 Independent SAP Technical User Group Thank You for AttendingThank You for Attending Pleasecompleteyour session feedbackPleasecompleteyour session feedback formform