Download - Just-in-Time Indexes
![Page 1: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/1.jpg)
Just-in-Time Indexes
Understanding Indexes in KB_SQL
March 2001
March 2001
![Page 2: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/2.jpg)
Learning Objectives
• What options do I have to improve query performance?
The answer is…indexes.
• Review indexing strategies
• Introduce just-in-time indexes
• Discuss advantages and caveats
![Page 3: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/3.jpg)
Improve Performance
Why does my query run so slow?
![Page 4: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/4.jpg)
Query Results
![Page 5: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/5.jpg)
Show Plan/Stats: Query
Run query with Show Plan and Show Stats
![Page 6: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/6.jpg)
Show Plan: Results
Note: No index being used
![Page 7: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/7.jpg)
Show Stats: Results
Note: Selecting 9 of 25000 rows searched
![Page 8: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/8.jpg)
Show All Plans: Query
Run query with SHOW_ALL_PLANS to see if index is available
![Page 9: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/9.jpg)
Show All Plans: Results
Note: No indexes available
![Page 10: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/10.jpg)
Index Exists
![Page 11: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/11.jpg)
Define Index to KB_SQL
Add BY_NAME index in KB_SQL
![Page 12: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/12.jpg)
New Show Plan
Note: BY_NAME index is used, cost is reduced
![Page 13: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/13.jpg)
New Show Stats
Note: Selecting 9 of 9 rows searched
![Page 14: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/14.jpg)
New Show All Plans
Note: BY_NAME index available
![Page 15: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/15.jpg)
How do we improve performance if we don’t have sufficient indexes?
• What are the options?– Create supplemental table(s)– Build index– Create just-in-time index
• When will it be populated?
• How often should it be updated?
• Advantages and caveats?
![Page 16: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/16.jpg)
Create Supplemental Tables
• Create new table
• Join to “base” table
![Page 17: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/17.jpg)
Build the Index
• Benefits– Queries only look at key data which results
in faster searches
• Caveats– Time– Resources– Additional globals to maintain
![Page 18: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/18.jpg)
What if there is no index?
![Page 19: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/19.jpg)
What if there is no index? (cont)
![Page 20: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/20.jpg)
What if there is no index? (cont)
![Page 21: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/21.jpg)
Just-in-Time Indexes
• When will the index be populated?
• How often should the index be updated?
![Page 22: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/22.jpg)
Just-in-Time Indexes: Advantages and Caveats
• Advantages over traditional indexes– Add only the indexes that the user
demands– Reduce wasted effort to build indexes that
won’t be used• Caveats
– Does not provide up-to-the-minute data accuracy
– 2 or more queries to realize benefit
![Page 23: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/23.jpg)
Build the Just-in-Time Index
![Page 24: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/24.jpg)
Define the Index to KB_SQL
![Page 25: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/25.jpg)
New Show All Plans
Note: Two indexes available; BY_SUPPLIER is accepted based on constraint
![Page 26: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/26.jpg)
New Show Plan
Note: BY_SUPPLIER index is used
![Page 27: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/27.jpg)
New Show Stats
Note: Selecting 4 of 4 rows searched
![Page 28: Just-in-Time Indexes](https://reader035.vdocument.in/reader035/viewer/2022062314/56813b77550346895da48aa2/html5/thumbnails/28.jpg)
Summary
• Discussed options available to help improve query performance
The answer is…indexes.
• Reviewed indexing strategies
• Introduced just-in-time indexes
• Discussed advantages and caveats