From: drh Date: Wed, 31 Aug 2005 03:13:12 +0000 (+0000) Subject: Refinements to the optimizer overview and integration into the website. (CVS 2649) X-Git-Tag: version-3.6.10~3510 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a91965b38a28277b550f1306d2fa9eb4c9f4ff58;p=thirdparty%2Fsqlite.git Refinements to the optimizer overview and integration into the website. (CVS 2649) FossilOrigin-Name: ccd12e9e790e271cb1dbbae1c13e9cb980eaf11d --- diff --git a/manifest b/manifest index 62d8d0550b..e5f0baa90a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sthe\sFAQ\sto\sinclude\san\sentry\sabout\sbinary\sversus\sdecimal\snumbers.\s(CVS\s2648) -D 2005-08-31T02:46:21 +C Refinements\sto\sthe\soptimizer\soverview\sand\sintegration\sinto\sthe\swebsite.\s(CVS\s2649) +D 2005-08-31T03:13:12 F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -276,7 +276,7 @@ F www/datatype3.tcl 1d14f70ab73075556b95e76a5c13e5b03f7f6c47 F www/datatypes.tcl 7c786d2e8ff434346764534ec015966d17efce60 F www/different.tcl d01064946c588db0a0e87563a30aef1b3efb4434 F www/direct1b.gif 32b48b764244817b6b591898dc52a04299a7b8a7 -F www/docs.tcl 6c0b2c567404b15bd46a0cda2dc69615a8e679a8 +F www/docs.tcl 8fec3341bb9b0d0b09a0d4e33055825cdd69642c F www/download.tcl ceaa742d5b8137bce31e9dcc4e44494b38211490 F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c F www/faq.tcl cdeb014235ac8030da593bde14a53240d4daa613 @@ -295,7 +295,7 @@ F www/omitted.tcl f1e57977299c3ed54fbae55e4b5ea6a64de39e19 F www/opcode.tcl 5bd68059416b223515a680d410a9f7cb6736485f F www/optimizer.tcl d6812a10269bd0d7c488987aac0ad5036cace9dc F www/optimizing.tcl f0b2538988d1bbad16cbfe63ec6e8f48c9eb04e5 -F www/optoverview.tcl e16344994a91318965d573ecc9ef2848153d5bf0 +F www/optoverview.tcl b282361a505bddf85c43217095a66f47dbf6c788 F www/pragma.tcl 44f7b665ca598ad24724f35991653638a36a6e3f F www/quickstart.tcl 6f6f694b6139be2d967b1492eb9a6bdf7058aa60 F www/speed.tcl 656ed5be8cc9d536353e1a96927b925634a62933 @@ -306,7 +306,7 @@ F www/tclsqlite.tcl 3df553505b6efcad08f91e9b975deb2e6c9bb955 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 4c8d0a4c26e44088ffb9f21aa7641a5ebd0058be -R 8c9dcafaf8c56c90363aaddb93c3711c +P 0bbe73fccfe52700c2ae1122388764e81a78bc22 +R 116e86a3585b21a6c570826363946445 U drh -Z e855546ae219fc0150427c3e7e1f6fde +Z 913c62cd31e3948a6b55fd91fd72e91a diff --git a/manifest.uuid b/manifest.uuid index ad28f4be7f..94db58d0ac 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0bbe73fccfe52700c2ae1122388764e81a78bc22 \ No newline at end of file +ccd12e9e790e271cb1dbbae1c13e9cb980eaf11d \ No newline at end of file diff --git a/www/docs.tcl b/www/docs.tcl index 981b2ab66f..fb425d104f 100644 --- a/www/docs.tcl +++ b/www/docs.tcl @@ -1,7 +1,7 @@ # This script generates the "docs.html" page that describes various # sources of documentation available for SQLite. # -set rcsid {$Id: docs.tcl,v 1.11 2005/03/19 14:45:50 drh Exp $} +set rcsid {$Id: docs.tcl,v 1.12 2005/08/31 03:13:12 drh Exp $} source common.tcl header {SQLite Documentation} puts { @@ -38,16 +38,17 @@ doc {SQL Syntax} {lang.html} { This document describes the SQL language that is understood by SQLite. } +doc {Version 3 C/C++ API
Reference} {capi3ref.html} { + This document describes each API function separately. +} +doc {Tcl API} {tclsqlite.html} { + A description of the TCL interface bindings for SQLite. +} doc {Pragma commands} {pragma.html} { This document describes SQLite performance tuning options and other special purpose database commands. } - -doc {Version 2 C/C++ API} {c_interface.html} { - A description of the C/C++ interface bindings for SQLite through version - 2.8 -} doc {SQLite Version 3} {version3.html} { A summary of of the changes between SQLite version 2.8 and SQLite version 3.0. } @@ -55,12 +56,11 @@ doc {Version 3 C/C++ API} {capi3.html} { A description of the C/C++ interface bindings for SQLite version 3.0.0 and following. } -doc {Version 3 C/C++ API
Reference} {capi3ref.html} { - This document describes each API function separately. -} - -doc {Tcl API} {tclsqlite.html} { - A description of the TCL interface bindings for SQLite. +doc {Version 3 DataTypes } {datatype3.html} { + SQLite version 3 introduces the concept of manifest typing, where the + type of a value is associated with the value itself, not the column that + it is stored in. + This page describes data typing for SQLite version 3 in further detail. } doc {Locking And Concurrency
In SQLite Version 3} {lockingv3.html} { @@ -68,20 +68,11 @@ doc {Locking And Concurrency
In SQLite Version 3} {lockingv3.html} { concurrancy and decreases the problem of writer starvation. } -doc {Version 2 DataTypes } {datatypes.html} { - A description of how SQLite version 2 handles SQL datatypes. - Short summary: Everything is a string. -} -doc {Version 3 DataTypes } {datatype3.html} { - SQLite version 3 introduces the concept of manifest typing, where the - type of a value is associated with the value itself, not the column that - it is stored in. - This page describes data typing for SQLite version 3 in further detail. +doc {Overview Of The Optimizer} {optoverview.html} { + A quick overview of the various query optimizations that are + attempted by the SQLite code generator. } -doc {Release History} {changes.html} { - A chronology of SQLite releases going back to version 1.0.0 -} doc {Null Handling} {nulls.html} { Different SQL database engines handle NULLs in different ways. The @@ -98,6 +89,22 @@ doc {Unsupported SQL} {omitted.html} { This page describes features of SQL that SQLite does not support. } +doc {Version 2 C/C++ API} {c_interface.html} { + A description of the C/C++ interface bindings for SQLite through version + 2.8 +} + + +doc {Version 2 DataTypes } {datatypes.html} { + A description of how SQLite version 2 handles SQL datatypes. + Short summary: Everything is a string. +} + +doc {Release History} {changes.html} { + A chronology of SQLite releases going back to version 1.0.0 +} + + doc {Speed Comparison} {speed.html} { The speed of version 2.7.6 of SQLite is compared against PostgreSQL and MySQL. diff --git a/www/optoverview.tcl b/www/optoverview.tcl index 38bc981b70..7f6b78edfd 100644 --- a/www/optoverview.tcl +++ b/www/optoverview.tcl @@ -1,7 +1,7 @@ # # Run this TCL script to generate HTML for the goals.html file. # -set rcsid {$Id: optoverview.tcl,v 1.1 2005/08/31 01:50:00 drh Exp $} +set rcsid {$Id: optoverview.tcl,v 1.2 2005/08/31 03:13:12 drh Exp $} source common.tcl header {The SQLite Query Optimizer Overview} @@ -58,7 +58,7 @@ HEADING 0 {The SQLite Query Optimizer Overview} PARAGRAPH { This document provides a terse overview of how the query optimizer - for SQLite works. This is not a tutoral. Some prior knowledge of how + for SQLite works. This is not a tutorial. Some prior knowledge of how database engines operate is likely needed in order to fully understand this text. } @@ -411,7 +411,7 @@ PARAGRAPH { If, however, all columns that were to be fetched from the table are already available in the index itself, SQLite will use the values contained in the index and will never look up the original table - row. This saves a binary search for each table and can make many + row. This saves one binary search for each row and can make many queries run twice as fast. } @@ -441,11 +441,48 @@ PARAGRAPH { To overcome this problem, SQLite attempts to flatten subqueries in the FROM clause of a SELECT. This involves inserting the FROM clause of the subquery into the - FROM clause of the outer query and rewriting certain expressions in - the outer query. - There is a long list of conditions that must be met in order for - query flattening to occur. These conditions are fully documented in - source code comments in the select.c source file. + FROM clause of the outer query and rewriting expressions in + the outer query that refer to the result set of the subquery. + For example: +} +CODE { + SELECT a FROM (SELECT x+y AS a FROM t1 WHERE z<100) WHERE a>5 +} +PARAGRAPH { + Would be rewritten using query flattening as: +} +CODE { + SELECT x+y AS a FROM t1 WHERE z<100 AND a>5 +} +PARAGRAPH { + There is a long list of conditions that must all be met in order for + query flattening to occur. +} +PARAGRAPH { +
    +
  1. The subquery and the outer query do not both use aggregates.
  2. +
  3. The subquery is not an aggregate or the outer query is not a join.
  4. +
  5. The subquery is not the right operand of a left outer join, or + the subquery is not itself a join.
  6. +
  7. The subquery is not DISTINCT or the outer query is not a join.
  8. +
  9. The subquery is not DISTINCT or the outer query does not use + aggregates.
  10. +
  11. The subquery does not use aggregates or the outer query is not + DISTINCT.
  12. +
  13. The subquery has a FROM clause.
  14. +
  15. The subquery does not use LIMIT or the outer query is not a join.
  16. +
  17. The subquery does not use LIMIT or the outer query does not use + aggregates.
  18. +
  19. The subquery does not use aggregates or the outer query does not + use LIMIT.
  20. +
  21. The subquery and the outer query do not both have ORDER BY clauses.
  22. +
  23. The subquery is not the right term of a LEFT OUTER JOIN or the + subquery has no WHERE clause.
  24. +
+} +PARAGRAPH { + The proof that query flattening may safely occur if all of the the + above conditions are met is left as an exercise to the reader. } PARAGRAPH { Query flattening is an important optimization when views are used as @@ -455,7 +492,7 @@ PARAGRAPH { HEADING 1 {The MIN/MAX optimization} minmax PARAGRAPH { - Queries of the following forms will be optimized to run in logorithmic + Queries of the following forms will be optimized to run in logarithmic time assuming appropriate indices exist: } CODE { @@ -465,5 +502,7 @@ CODE { PARAGRAPH { In order for these optimizations to occur, they must appear in exactly the form shown above - changing only the name of the table and column. + It is not permissible to add a WHERE clause or do any arithmetic on the + result. The result set must contain a single column. And the column in the MIN or MAX function must be an indexed column. }