Indexing Examples

Outline

TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Examples

  • Consider a relational table
    PRODUCT(PNUM, PNAME, PRICE, MANUFACTURER)
  • Assume that
    • the table contains 105 rows,
    • an attribute PNUM is a primary key,
    • the products are manufactured by 100 manufacturers,
    • the table contains 1000 product names,
    • an average number of rows per disk block (blocking factor) is 50
    • a database administrator created a non-clustered B*-tree index on attribute MANUFACTURER,
    • a fanout of B*-tree is equal to f
    • a width (total number of blocks at leaf level) of B*-tree implementing an index on the primary key is equal to wp
    • a width (total number of blocks at leaf level) of B*-tree implementing an index on an attribute MANUFACTURER is equal to wm
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 1

  • To compute a query
      
      SELECT PNAME, PRICE
      FROM  PRODUCT;
  • we have to read105/50 (total number of rows/blocking factor) blocks because the entire relational table PRODUCT must be read
  • A fragment of respective query processing plan
      
      -------------------------------------------- ...
      | Id | Operation          | Name    |
      -------------------------------------------- ...
      | 0  | SELECT STATEMENT   |         |
      | 1  |  TABLE ACCESS FULL | PRODUCT |
      -------------------------------------------- ...
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 2

  • To compute a query
      
      SELECT PNAME, PRICE
      FROM  PRODUCT
      WHERE PNUM = 12345;
  • we have to read [logf105 +1] + 1 blocks because the primary key PNUM is automatically indexed
  • A fragment of respective query processing plan
      
      ----------------------------------------------------- ...
      | Id | Operation                    | Name         |
      ----------------------------------------------------- ...
      | 0  | SELECT STATEMENT             |              |
      | 1  |  TABLE ACCESS BY INDEX ROWID | PRODUCT      |
      |*2  |   INDEX UNIQUE SCAN          | PRODUCT_PKEY |
      ----------------------------------------------------- ...
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 3

  • To compute a query
      
      SELECT PNAME, PRICE
      FROM  PRODUCT
      WHERE PNUM = 1234567 AND
            PRICE <= 20.0;
  • we have to read [logf105 +1] + 1 blocks because the primary key PNUM is automatically indexed
  • A fragment of respective query processing plan
      
      ----------------------------------------------------- ...
      | Id | Operation                    | Name         |
      ----------------------------------------------------- ...
      | 0  | SELECT STATEMENT             |              |
      | 1  |  TABLE ACCESS BY INDEX ROWID | PRODUCT      |
      |*2  |   INDEX UNIQUE SCAN          | PRODUCT_PKEY |
      ----------------------------------------------------- ...
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 4

  • To compute a query
      
      SELECT PNAME, PRICE
      FROM  PRODUCT
      WHERE PNUM = 1234567 OR
            PRICE <= 20.0;
  • we have to read 105/50 (total number of rows/blocking factor) blocks because the entire relational table PRODUCT must be read
      
      -------------------------------------------- ...
      | Id | Operation          | Name    |
      -------------------------------------------- ...
      | 0  | SELECT STATEMENT   |         |
      | 1  |  TABLE ACCESS FULL | PRODUCT |
      -------------------------------------------- ...
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 5

  • To compute a query
      
      SELECT PNAME, PRICE
      FROM  PRODUCT
      WHERE MANUFACTURER = 'GoldenBolts';
  • we have to read
    [logf102 + 1] + ((105/100) + 105/(100*50))/2 data blocks
  • Index processing: [logf102 + 1] read block operations
  • Total number of row identifiers found: 105/100
  • Table processing:
    • The best case (full clustering: 105/(100*50) read block operations
    • The worst case (each row in a different block): 105 /100 read block operations
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 5 (continuation)

  • To compute a query
      
      SELECT PNAME, PRICE
      FROM  PRODUCT
      WHERE MANUFACTURER = 'GoldenBolts';
  • we have to read
    [logf102 + 1] + ((105/100) + 105/(100*50))/2 data blocks
      
      --------------------------------------------------- ...
      | Id | Operation                    | Name    |
      --------------------------------------------------- ...
      | 0  | SELECT STATEMENT             |         |
      | 1  |  TABLE ACCESS BY INDEX ROWID | PRODUCT |
      |*2  |   INDEX RANGE SCAN           | PIDX    |
      --------------------------------------------------- ...
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 6

  • To compute a query
      
      SELECT COUNT(*)
      FROM PRODUCT;
  • we have to read wp data blocks (width of leaf level on an index on primary key)
  • Index processing: wp read block operations
  • Counting row identifiers: 0 read block operations, counting is performed in transient memory
      
      ----------------------------------------------- ...
      | Id | Operation             | Name         |
      ----------------------------------------------- ...
      | 0  | SELECT STATEMENT      |              |
      | 1  |  SORT AGGREGATE       |              |
      | 2  |   INDEX FAST FULL SCAN| PRODUCT_PKEY |
      ----------------------------------------------- ...
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 7

  • To compute a query
      
      SELECT COUNT(*)
      FROM  PRODUCT;
      WHERE MANUFACTURER = 'GoldenBolts';
  • we have to read [logf102 +1] data blocks
  • Index processing: [logf102 +1] read block operations
  • Counting row identifiers: 0 read block operations, counting is performed in transient memory
      -------------------------------------------- ...
      | Id | Operation          | Name  |
      -------------------------------------------- ...
      | 0  | SELECT STATEMENT   |       |
      | 1  |  SORT AGGREGATE    |       |
      |*2  |   INDEX RANGE SCAN | PIDX  |
      -------------------------------------------- ...
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 8

  • To compute a query
      
      SELECT MANUFACTURER
      FROM  PRODUCT
      WHERE MANUFACTURER LIKE 'M%';
  • we have to read wm data blocks (width of a leaf level of an index on MANUFACTURER)
  • Index processing: wm read block operations
      
      -------------------------------------------- ...
      | Id | Operation         | Name |
      -------------------------------------------- ...
      | 0  | SELECT STATEMENT  |      |
      |*1  |  INDEX RANGE SCAN | PIDX |
      -------------------------------------------- ... 
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 9

  • To compute a query
      
      SELECT DISTINCT MANUFACTURER
      FROM  PRODUCT;
  • we have to read wm data blocks
  • Index processing: wm read block operations (horizontal traversal through leaf level on an index on MANUFACTURER)
      
      ---------------------------------------------- ...
      | Id | Operation             | Name         |
      ---------------------------------------------- ...
      | 0  | SELECT STATEMENT      |              |
      | 1  |  SORT UNIQUE          |              |
      | 2  |   INDEX FAST FULL SCAN| PRODUCT_PKEY |
      ---------------------------------------------- ...
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 10

  • To compute a query
      
      SELECT MANUFACTURER, COUNT(*)
      FROM PRODUCT
      GROUP BY MANUFACTURER;
  • we have to read wm data blocks
  • Index processing: wm read block operations
      
      --------------------------------------------- ...
      | Id | Operation            | Name         |
      --------------------------------------------- ...
      | 0  | SELECT STATEMENT     |              |
      | 1  |  SORT GROUP BY NOSORT|              |
      | 2  |   INDEX FULL SCAN    | PRODUCT_PKEY |
      --------------------------------------------- ...
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Examples (continuation)

  • Consider a relational table
    PRODUCT(PNUM, PNAME, PRICE, MANUFACTURER)
  • Assume that
    • a database administrator created a non-clustered B*-tree index on attribute PNAME,
    • the table contains 1000 distinct product name
    • a fanout of B*-tree is equal to f
    • a width (total number of blocks at leaf level) of B*-tree implementing an index on an attribute PNAME is equal to wn
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 10

  • To compute a query
      
      SELECT *
      FROM PRODUCT
      WHERE PNAME = 'bolt' AND
            MANUFACTURER = 'Golden Bolts';
  • we have to read [logf1000 +1] + [logf100 +1] + 1 data blocks
  • Index processing: [logf1000 +1] read block operations to process an index on PNAME
  • The total number of row identifiers found: 105/1000
  • Index processing: [logf100 +1]read block operations to process an index on MANUFACTURER
  • The total number of row identifiers found: 105/100
  • Intersection of the sets of row identifiers obtained from index processing: 0 read block operations
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 10

  • Total number of row identifiers found: 105/(1000*100) = 1
  • Table processing: 1 read block operations
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 11

  • To compute a query
      
      SELECT *
      FROM PRODUCT
      WHERE PNAME = 'bolt' OR
            MANUFACTURER = 'Golden Bolts';
  • we have to read [logf1000 +1] + [logf100 +1] + ((102 + 103 - 1) + (102 + 103 - 1)/50)/2 data blocks
  • Index processing: [logf1000 +1] read block operations to process an index on PNAME
  • The total number of row identifiers found: 105/1000
  • Index processing: [logf100 +1]read block operations to process an index on MANUFACTURER
  • The total number of row identifiers found: 105/100
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 11

  • Union of the sets of row identifiers obtained from index processing: 0 read block operations
  • Total number of row identifiers found: (105/1000) +(105/100) - (105/(1000*100)) = 102 +103 - 1
  • Table processing: ((102 +103 - 1) + (102 +103 - 1)/50)/2 read block operations
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

Example 12

  • To compute a query
      
      SELECT 	*
      FROM PRODUCT
      WHERE PNAME > 'bolt';
  • we have to read [logf1000 +1] + wp*n/105 + (n + n/50)/2 data blocks
  • Vertical index processing: [logf1000 +1] read block operations to process an index on PNAME
  • Horizontal index processing: wp*n/105 where wp is the total number of leaf level blocks and n is the total number of rows that satisfy a condition PNAME > 'bolt'
TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022

References

TOP          Created by Janusz R. Getta, CSCI317 Database Performance Tuning, SIM, Session 3, 2022