lang_indexedby.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html><head>
  3. <title>SQLite Query Language: INDEXED BY</title>
  4. <style type="text/css">
  5. body {
  6. margin: auto;
  7. font-family: Verdana, sans-serif;
  8. padding: 8px 1%;
  9. }
  10. a { color: #45735f }
  11. a:visited { color: #734559 }
  12. .logo { position:absolute; margin:3px; }
  13. .tagline {
  14. float:right;
  15. text-align:right;
  16. font-style:italic;
  17. width:240px;
  18. margin:12px;
  19. margin-top:58px;
  20. }
  21. .toolbar {
  22. font-variant: small-caps;
  23. text-align: center;
  24. line-height: 1.6em;
  25. margin: 0;
  26. padding:1px 8px;
  27. }
  28. .toolbar a { color: white; text-decoration: none; padding: 6px 12px; }
  29. .toolbar a:visited { color: white; }
  30. .toolbar a:hover { color: #80a796; background: white; }
  31. .content { margin: 5%; }
  32. .content dt { font-weight:bold; }
  33. .content dd { margin-bottom: 25px; margin-left:20%; }
  34. .content ul { padding:0px; padding-left: 15px; margin:0px; }
  35. /* rounded corners */
  36. .se { background: url(images/se.png) 100% 100% no-repeat #80a796}
  37. .sw { background: url(images/sw.png) 0% 100% no-repeat }
  38. .ne { background: url(images/ne.png) 100% 0% no-repeat }
  39. .nw { background: url(images/nw.png) 0% 0% no-repeat }
  40. </style>
  41. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  42. </head>
  43. <body>
  44. <div><!-- container div to satisfy validator -->
  45. <a href="lang.html">
  46. <h2 align="center">SQL As Understood By SQLite</h2></a><h1>INDEXED BY</h1>
  47. <p>The INDEXED BY phrase is a SQL extension found only in SQLite which can
  48. be used to verify that the correct indices are being used on a <a href="lang_delete.html">DELETE</a>,
  49. <a href="lang_select.html">SELECT</a>, or <a href="lang_update.html">UPDATE</a> statement.
  50. The INDEXED BY phrase always follows the name of a table that SQLite will
  51. be reading. The INDEXED BY phrase can be seen in the following syntax
  52. diagrams:</p>
  53. <h4><a href="syntaxdiagrams.html#qualified-table-name">qualified-table-name:</a></h4><blockquote> <img alt="syntax diagram qualified-table-name" src="images/syntax/qualified-table-name.gif"></img> </blockquote>
  54. <h4><a href="syntaxdiagrams.html#single-source">single-source:</a></h4><blockquote> <img alt="syntax diagram single-source" src="images/syntax/single-source.gif"></img> </blockquote>
  55. <p>The "INDEXED BY index-name" clause specifies that the named index
  56. must be used in order to look up values on the preceding table.
  57. If index-name does not exist or cannot be used for the query, then
  58. the preparation of the SQL statement fails.
  59. The "NOT INDEXED" clause specifies that no index shall be used when
  60. accessing the preceding table, including implied indices create by
  61. UNIQUE and PRIMARY KEY constraints. However, the INTEGER PRIMARY KEY
  62. can still be used to look up entries even when "NOT INDEXED" is specified.</p>
  63. <p>Some SQL database engines provide non-standard "hint" mechanisms which
  64. can be used to give the query optimizer clues about what indices it should
  65. use for a particular statement. The INDEX BY clause of SQLite is
  66. <em>not</em> a hinting mechanism and it should not be used as such.
  67. The INDEXED BY clause does not give the optimizer hints about which index
  68. to use; it gives the optimizer a requirement of which index to use.
  69. If the query optimizer is unable to use the index specified by the
  70. INDEX BY clause, then the query will fail with an error.</p>
  71. <p>The INDEXED BY clause is <em>not</em> intended for use in tuning
  72. the preformance of a query. The intent of the INDEXED BY clause is
  73. to raise a run-time error if a schema change, such as dropping or
  74. creating an index, causes the query plan for a time-sensitive query
  75. to change. The INDEXED BY clause is designed to help detect
  76. undesirable query plan changes during regression testing.
  77. Developers are admonished to omit all use of INDEXED BY during
  78. application design, implementation, testing, and tuning. If
  79. INDEXED BY is to be used at all, it should be inserted at the very
  80. end of the development process when "locking down" a design.</p>
  81. <h3>See Also:</h3>
  82. <p>The sqlite3_stmt_status() C/C++ interface together with the
  83. SQLITE_STMTSTATUS_FULLSCAN_STEP and SQLITE_STMTSTATUS_SORT verbs
  84. can be used to detect at run-time when an SQL statement is not
  85. making effective use of indices. Many applications may prefer to
  86. use the sqlite3_stmt_status() interface to detect index misuse
  87. rather than the INDEXED BY phrase described here.</p>
  88. <DIV class="pdf_section">