sql: enable ephemeral index optimization
This patch enables "ephemeral index" optimization (which is called Automatic Indexes in the original SQLite implementation). The main idea behind the optimization is to create temporary (ephemeral) space that lasts only the duration of single SQL statement. Such space stores intermediate execution results. Since in Tarantool index can't exist without space (in contrast to SQLite) we call this optimization "ephemeral index". It may turn out beneficial due to the fact that cost of creating and filling space with single index is (NlogN). So if we lookup data more than logN times during the query execution, ephemeral index may give as better timings (space full-scan is still O(N)). As a rule "ephemeral index" space relates to one of spaces used in query and contains all or fewer fields than the original space. The order of fields in ephemeral space may be different from order in the original space. In addition to the mentioned fields, ephemeral index has a rowid - additional unsigned field with non-decreasing values which allows to store not unique values. Example: CREATE TABLE t1 (i INT PRIMARY KEY, a INT, b INT, c INT); CREATE TABLE t2 (i INT PRIMARY KEY, a INT, b INT, c INT); ... SELECT t1.a, t2.b FROM t1, t2 WHERE t1.b = t2.c In case the planner decides to use an ephemeral index and chooses t1 as the source space, an ephemeral index with three fields will be created and will contain the values from t1.b, t1.a, and rowid in that order. If t2 is chosen as the source space, an ephemeral index will contain the values from t2.c, t2.b, and rowid. This optimization can also be applied to store results of subquery evaluation. Closes #4933 Co-authored-by:Mergen Imeev <imeevma@gmail.com> Co-authored-by:
Timur Safin <tsafin@tarantool.org> Reviewed-by:
Nikita Pettik <korablev@tarantool.org>
Showing
- src/box/CMakeLists.txt 1 addition, 1 deletionsrc/box/CMakeLists.txt
- src/box/sql.c 1 addition, 1 deletionsrc/box/sql.c
- src/box/sql/delete.c 0 additions, 40 deletionssrc/box/sql/delete.c
- src/box/sql/sqlInt.h 0 additions, 35 deletionssrc/box/sql/sqlInt.h
- src/box/sql/where.c 163 additions, 98 deletionssrc/box/sql/where.c
- src/box/sql/wherecode.c 7 additions, 6 deletionssrc/box/sql/wherecode.c
- test/sql-tap/autoindex1.test.lua 122 additions, 0 deletionstest/sql-tap/autoindex1.test.lua
- test/sql-tap/autoindex4.test.lua 13 additions, 1 deletiontest/sql-tap/autoindex4.test.lua
- test/sql-tap/whereF.test.lua 13 additions, 3 deletionstest/sql-tap/whereF.test.lua
- test/sql/misc.result 30 additions, 0 deletionstest/sql/misc.result
- test/sql/misc.test.lua 9 additions, 0 deletionstest/sql/misc.test.lua
Loading
Please register or sign in to comment