O - Oracle 19c Automatic Indexing Inside Out
O - Oracle 19c Automatic Indexing Inside Out
• Works incrementally
– So needs to be iterative and continuous
– Created as invisible
o Uses ‘SYS_AI’ as the name prefix
– Automatic indexes are tested
o If improved performance – indexes made visible
o If no improvement – indexes are marked unusable
> Later removed
4 quest.com | confidential
19c Automatic Indexing High Level Steps
• No DBA interaction
• All tuning activities
– Auditable via reporting
Capture
Monitor Identify
Online
Verify
Validation
Decide
5 quest.com | confidential
19c Automatic Indexing – How It Works
• Capture
– Captures the application SQL history into a SQL repository
– Includes SQL, plans, bind values, execution statistics, etc. Capture
• Online Validation
– Validation of new indexes continues for other statements online
– Only one of the sessions executing a SQL statement
Capture
• Monitor Online
Validation
Verify
Decide
Production Database
CPU Task
Memory Build
Storage Store
9 quest.com | confidential
Automatic Indexing Requirements
• Feature is only available to Enterprise Edition on Engineered Systems
– Exadata only
11 quest.com | confidential
Configure.Auto_Index_Mode Example
12 quest.com | confidential
Configure.Auto_Index_Schema Example
13 quest.com | confidential
DBMS_AUTO_INDEX.CONFIGURE - Cont.
– CONFIGURE
o AUTO_INDEX_RETENTION_FOR_AUTO
> Number of days (default 373) auto indexes retained after last used date
o AUTO_INDEX_RETENTION_FOR_MANUAL
> Number of days (default NULL) manual indexes retained after last used date
o AUTO_INDEX_REPORT_RETENTION
> Number of days automatic indexing logs are retained before deletion
> Automatic indexing report is based of the logs (Default is 31 days)
o AUTO_INDEX_DEFAULT_TABLESPACE
> Tablespace to use to store auto indexes (Default is NULL)
o AUTO_INDEX_SPACE_BUDGET
> Percentage of tablespace size to use for auto indexes
> Can only be used when using default tablespace is used
14 quest.com | confidential
DBMS_AUTO_INDEX.CONFIGURE - Cont.
– CONFIGURE additional commands
o PARAMETER_VALUE is specific to parameter
> If NULL, setting is assigned a default value
o AUTO_INDEX_COMPRESSION enables/disables advanced compression
> ON for Advanced Low Compression
> OFF for no compression (Default)
o ALLOW for AUTO_INDEX_SCHEMA parameter
> TRUE adds the specified schema to the inclusion list
> FALSE adds the schema to the exclusion list
> NULL remove the schema from the list that it is currently added
15 quest.com | confidential
DBMS_AUTO_INDEX.CONFIGURE Examples
16 quest.com | confidential
DBMS_AUTO_INDEX.CONFIGURE Examples
17 quest.com | confidential
New (CDB/DBA) Views for Auto Indexes
• DBA_AUTO_INDEX_CONFIG *
– Display the current configuration of the automation index
• DBA_AUTO_INDEX_EXECUTIONS
– History of Automatic Indexing task executions
• DBA_AUTO_INDEX_IND_ACTIONS
– Actions performed on automatic indexes (e.g create, rebuild, etc…)
• DBA_AUTO_INDEX_SQL_ACTIONS
– Actions performed on SQL to verify automatic indexes
• DBA_AUTO_INDEX_STATISTICS
– Shows statistics related to automatic indexes
• DBA_AUTO_INDEX_VERIFICATIONS
– Shows statistics about PLAN_HASH_VALUE (original buffer gets, etc…)
18 quest.com | confidential
Additional Views for Auto Indexes
• DBA_ADVISOR_TASKS – new tasks
19 quest.com | confidential
SMB$CONFIG Table
• Shows both documented & undocumented settings for Auto Indexes
20 quest.com | confidential
Other DBMS_AUTO_INDEX Functions
• DROP_SECONDARY_INDEXES
– Deletes all the indexes, except the ones used for constraints
o From a schema or a table
o Example - begin dbms_auto_index.drop_secondary_indexes('SH'); end;
22 quest.com | confidential
Report_Activity Example
23 quest.com | confidential
Report_Activity Cont.
24 quest.com | confidential
Report_Activity Cont.
25 quest.com | confidential
Other DBMS_AUTO_INDEX Procedures
• REPORT_LAST_ACTIVITY - Returns a report of the latest operation
declare
report clob := null; select dbms_auto_index.report_last_activity() from dual;
begin
report := DBMS_AUTO_INDEX.REPORT_LAST_ACTIVITY (
type => 'TEXT',
section=> 'ALL',
level=> 'TYPICAL');
dbms_output.put_line(report);
end;
26 quest.com | confidential
3 Case Studies
• Tuning Examples
– Used throughout the years with many Oracle versions – 10 & up
– Manual results were compared with the Tuning Advisor suggestions
o Consistent in previous releases
> Advisor usually missed the mark or got close but required additional DBA intervention
27 quest.com | confidential
Billing Query for a University
• Slow performance was reported by a customer
– Having trouble with their billing system
– The following query was identified as performing poorly
SELECT s.fname, s.lname, r.signup_date
FROM student s
INNER JOIN registration r ON s.student_id = r.student_id
INNER JOIN class c ON r.class_id = c.class_id
WHERE c.name = 'SQL TUNING'
AND r.signup_date BETWEEN
to_date(:beg_date,'DD-MON-YY') and to_date(:beg_date,'DD-MON-YY') +1
AND r.cancelled = 'N’;
– Table sizes
o Registration – 80,000 rows
o Student – 18,000 rows
o Class – 1000 rows
28 quest.com | confidential
Original Plan
29 quest.com | confidential
Original Performance
30 quest.com | confidential
Auto Indexes Enabled for Schema ‘Test’
31 quest.com | confidential
Review Process of Registration (class_id, canceled)
SELECT a.execution_name, a.table_name,
a.index_name, b.stat_name, a.start_time
FROM dba_auto_index_ind_actions a, dba_auto_index_statistics b
WHERE a.execution_name = b.execution_name
ORDER BY 5,3;
DBA_AUTO_INDEX_VERIFICATIONS
32 quest.com | confidential
Auto Indexes Created
• Shows status of indexes
– 2 indexes are taking up space
33 quest.com | confidential
With Compression
EXEC DBMS_AUTO_INDEX.CONFIGURE('AUTO_INDEX_COMPRESSION','ON');
34 quest.com | confidential
Report_Activity
35 quest.com | confidential
Report_Activity Cont.
36 quest.com | confidential
Auto Index Plan
37 quest.com | confidential
Auto Index on Registration
38 quest.com | confidential
With Auto Index
39 quest.com | confidential
DBA Tuned Query
40 quest.com | confidential
Best Performance
41 quest.com | confidential
Did it measure up?
Auto Cost
107 (class)
76 (reg)
42 quest.com | confidential
Sale Order Query
• HammerDB load utility – Slow running query
SELECT c_last, c_first, c_street_1, c_city, c_state, c_zip, Order_line 60,461,709
c_phone, o_entry_d, d_name, ol_delivery_d, ol_quantity, ol_amount
FROM order_line, orders, district, customer, stock
WHERE o_id = ol_o_id Orders 6,046,215
AND o_c_id=c_id
AND s_i_id = ol_i_id District 50
AND d_id = ol_d_id
AND ol_w_id = :B2
AND ol_d_id = :B4
Customer 150,000
AND (ol_o_id < :B3 )
AND ol_o_id >= (:B3 - 20) Stock 500,000
AND s_w_id = :B2
AND s_quantity < :B1
AND d_id = :B4
AND c_last like :B5 ;
43 quest.com | confidential
Existing Indexes
44 quest.com | confidential
Original Execution Plan
45 quest.com | confidential
Original Performance
46 quest.com | confidential
Include SOE Schema for Auto Indexing
SELECT index_name,table_name,
auto,visibility, compression,
segment_created, status
FROM user_indexes
WHERE auto='YES';
47 quest.com | confidential
Automatic Indexes
48 quest.com | confidential
New Execution Plan
49 quest.com | confidential
Performance
50 quest.com | confidential
DBA Fine Tunes the Query
• create index orders_i2 on orders(o_id,o_c_id, o_entry_d);
51 quest.com | confidential
Popular Airline Flights in USA
SELECT
o.carrier, uc.description AS carrier_name
,ao.description AS origin_airport,co.Description AS origin_city
,o.fl_date,o.fl_num,o.tail_num
,ad.description AS destination_airport
,cd.Description AS destination_city ,w.Description Day_of_Week
FROM t_ontime o
INNER JOIN L_UNIQUE_CARRIERS uc ON uc.Code = o.UNIQUE_CARRIER
INNER JOIN L_AIRPORT_ID ao ON ao.Code = o.ORIGIN_AIRPORT_ID
INNER JOIN L_AIRPORT_ID ad ON ad.Code = o.DEST_AIRPORT_ID
INNER JOIN L_CITY_MARKET_ID co ON co.Code = o.ORIGIN_CITY_MARKET_ID
INNER JOIN L_CITY_MARKET_ID cd ON cd.Code = o.DEST_CITY_MARKET_ID
INNER JOIN L_WEEKDAYS w ON w.Code = o.DAY_OF_WEEK
WHERE to_date(fl_date,'YYYY-MM-DD') BETWEEN &beg_date AND &end_date
AND co.Description = &city
AND w.Description = &day_of_week;
L_UNIQUE_CARRIERS: 1620
L_AIRPORT_ID: 6438
L_CITY_MARKET_ID: 5823 US DOT - On-time Performance
L_WEEKDAYS: 8
T_ONTIME: 6784044
52 quest.com | confidential
Only Access Path is Full Table Scans
• No Original Indexes
53 quest.com | confidential
Automatic Indexes
• Visible Indexes
54 quest.com | confidential
Automatic Index Report
select DBMS_AUTO_INDEX.REPORT_LAST_ACTIVITY('TEXT','ALL','ALL') from dual
55 quest.com | confidential
New Plan
56 quest.com | confidential
Original Performance
57 quest.com | confidential
Auto Index Performance
58 quest.com | confidential
Summary
• Automatic Indexing can speed up performance
– 19c Optimizer has come along way
• Beware of just turning it on blindly
– Especially in production
– Watch out for baselines
o Created even when you have ‘capture’ turned off
– Auto Indexes can be Invisible / Visible
• Consider using in development / test
– Be cautious using in production
• Control at schema level
• Turn on compression for space savings
59 quest.com | confidential