home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / DBDEMO.ZIP / DEMOFLS.ZIP / INDICES.TXT < prev    next >
Text File  |  1991-07-01  |  3KB  |  81 lines

  1.          Indices - Short Path to Data
  2.  
  3.  
  4. An INDEX is a list of record addresses, kept in order on
  5. one or more columns known as the keys.
  6.  
  7. This program shows the performance difference between Index and
  8. no-Indexed table.  Module indx() runs the query:
  9.  
  10.  
  11.        SELECT * FROM BMCHUGH.PERFDAT3
  12.        WHERE CU_SSN   BETWEEN  '111-11-1020' AND '111-11-1140';
  13.  
  14.  
  15. against table PERFDAT3 where an index has been defined on column
  16. CU_SSN. Since CU_SSN is the only column in the WHERE clause, the
  17. optimizer chose to do an INDEX SCAN.
  18.  
  19. Module noindex() runs the same query against PERFDAT4 where no
  20. indices have been defined and the optimizer is forced to do
  21. a TABLE SCAN (sequential search).
  22.  
  23.  
  24. CONCEPTS:
  25.  
  26. Optimizer, access plan, binding, CREATE INDEX, key.
  27.  
  28. WHY USE INDICES
  29.  
  30. Because the rows of the base table are unordered an
  31. index satisfies that ordering requirement, reduces disk
  32. access by retrieveing data without lengthy sequential searching,
  33. and reduces the number of records read.
  34.  
  35.  
  36. WHEN AN INDEX IS USED
  37.  
  38. The database manager optimizer uses an index whenever the index
  39. presents an efficient path to the data.
  40.  
  41. Consider the types of queries that are likely to be made
  42. against a table to decide whether certain indices will help
  43. their performance.
  44.  
  45.  
  46. PERFORMANCE  ADVANTAGE
  47.  
  48. Indices always exist on a primary key of larger tables.
  49. Creating the appropriate indices can reduce response time
  50. considerably in some situtations.
  51.  
  52. Optimizer may or may not decide to use an index:
  53.  
  54.  example 1. on small tables a table scan may be cheaper.
  55.  example 2. extracting a large number or rows.
  56.  
  57. It is much faster to import a table, and then create the index than
  58. to create the index and then import the table, Due to the added overhead of
  59. updating the index.
  60.  
  61. Creating indexes can reduce response time by 90% or more
  62. in certain situtations.
  63.  
  64.  
  65. PERFORMANCE  DISADVANTAGE
  66.  
  67. Any number of indices can be defined on a particular base table. However
  68. the more indices there are for a table, the more indexes database manager
  69. has to maintain during update, insert, or delete operations.
  70.  
  71. Indices do take space on the disk.
  72.  
  73.  
  74. RUNSTAT
  75.  
  76. The optimizer uses the system table statistics to determine whether
  77. an index wil be used or not.  The staitistics might get outdated
  78. over time.  Therefore after indices are created, execute the RUNSTATS
  79. utility to update the table statics.  Additionally, you must REBIND
  80. any application program that accesses the table so that a new
  81. access plan may be generated that is aware of the new index.