Freitag, Januar 06, 2012

Index-Größenschätzung durch Explain Plan

Heute ist mir zum ersten Mal aufgefallen, dass Explain Plan für ein CREATE INDEX eine Größenschätzung liefert:

explain plan for
create index idx_t1 on t1(a);

select * from table(dbms_xplan.display);

Plan hash value: 2186317495

---------------------------------------------------------------------------------
| Id  | Operation              | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------
|   0 | CREATE INDEX STATEMENT |        |   257K|  3264K|  1001   (1)| 00:00:13 |
|   1 |  INDEX BUILD NON UNIQUE| IDX_T1 |       |       |            |          |
|   2 |   SORT CREATE INDEX    |        |   257K|  3264K|            |          |
|   3 |    TABLE ACCESS FULL   | T1     |   257K|  3264K|   858   (1)| 00:00:11 |
---------------------------------------------------------------------------------

Note
-----
   - estimated index size: 7340K bytes

Bisher war ich nie auf die Idee gekommen, dass Explain Plan für einen Index interessant sein könnte. Der Versuch herauszufinden, seit wann diese Option existiert, hat mich dann mal wieder zu Randolf Geists Blog geführt, wo sich ein Artikel EXPLAIN PLAN on DDLs findet, der diese und manch andere Frage beantwortet:
Starting with Oracle 10.2 you'll get an indication of the size of the index based on the dictionary statistics in the "Notes" section, so the estimate is only as good as your statistics allow for, in addition above points apply regarding the accuracy of the estimate in case of null values or function-based indexes. The size estimate is obviously based on the average column length recorded in the statistics.
Insgesamt scheint die Aussagekraft der Schätzung allerdings recht beschränkt zu sein, da sie diverse relevant Punkte ignoriert (Anzahl NULLs, implizite Tablespace-Zuordnung, Kompression, FBI, keine Unterscheidung zwischen B*Tree und Bitmap), wie Randolf anhand praktischer Tests nachweist.

Nachtrag 08.01.2012: kaum schreibe ich darüber, da sehe ich, dass Jonathan Lewis gerade gezeigt hat, dass die Schätzung einen recht massiven Bug enthält (zumindest bis inklusive 11.2.0.2)

Nachtrag 24.04.2014: einen Artikel zum Thema gibt's jetzt auch von Richard Foote.

Keine Kommentare:

Kommentar veröffentlichen