mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Have the rtree module set the estimatedCost output variable. Ticket #3312. (CVS 5649)
FossilOrigin-Name: 483932c4e08901a11b7ab671073fd0a048b10d66
This commit is contained in:
@ -12,7 +12,7 @@
|
||||
** This file contains code for implementations of the r-tree and r*-tree
|
||||
** algorithms packaged as an SQLite virtual table module.
|
||||
**
|
||||
** $Id: rtree.c,v 1.7 2008/07/16 14:43:35 drh Exp $
|
||||
** $Id: rtree.c,v 1.8 2008/09/01 12:47:00 danielk1977 Exp $
|
||||
*/
|
||||
|
||||
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
|
||||
@ -1116,6 +1116,13 @@ static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
pIdxInfo->idxNum = 1;
|
||||
pIdxInfo->aConstraintUsage[ii].argvIndex = 1;
|
||||
pIdxInfo->aConstraintUsage[jj].omit = 1;
|
||||
|
||||
/* This strategy involves a two rowid lookups on an B-Tree structures
|
||||
** and then a linear search of an R-Tree node. This should be
|
||||
** considered almost as quick as a direct rowid lookup (for which
|
||||
** sqlite uses an internal cost of 0.0).
|
||||
*/
|
||||
pIdxInfo->estimatedCost = 10.0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@ -1169,6 +1176,8 @@ static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
if( iIdx>0 && 0==(pIdxInfo->idxStr = sqlite3_mprintf("%s", zIdxStr)) ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
assert( iIdx>=0 );
|
||||
pIdxInfo->estimatedCost = (2000000.0 / (double)(iIdx + 1));
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
111
ext/rtree/rtree6.test
Normal file
111
ext/rtree/rtree6.test
Normal file
@ -0,0 +1,111 @@
|
||||
# 2008 Sep 1
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: rtree6.test,v 1.1 2008/09/01 12:47:00 danielk1977 Exp $
|
||||
#
|
||||
|
||||
if {![info exists testdir]} {
|
||||
set testdir [file join [file dirname $argv0] .. .. test]
|
||||
}
|
||||
source $testdir/tester.tcl
|
||||
|
||||
ifcapable !rtree {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Operator Byte Value
|
||||
# ----------------------
|
||||
# = 0x41 ('A')
|
||||
# <= 0x42 ('B')
|
||||
# < 0x43 ('C')
|
||||
# >= 0x44 ('D')
|
||||
# > 0x45 ('E')
|
||||
# ----------------------
|
||||
|
||||
proc rtree_strategy {sql} {
|
||||
set ret [list]
|
||||
db eval "explain $sql" a {
|
||||
if {$a(opcode) eq "VFilter"} {
|
||||
lappend ret $a(p4)
|
||||
}
|
||||
}
|
||||
set ret
|
||||
}
|
||||
|
||||
proc query_plan {sql} {
|
||||
set ret [list]
|
||||
db eval "explain query plan $sql" a {
|
||||
lappend ret $a(detail)
|
||||
}
|
||||
set ret
|
||||
}
|
||||
|
||||
do_test rtree6-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t2(k INTEGER PRIMARY KEY, v);
|
||||
CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2);
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test rtree6-1.2 {
|
||||
rtree_strategy {SELECT * FROM t1 WHERE x1>10}
|
||||
} {Ea}
|
||||
|
||||
do_test rtree6-1.3 {
|
||||
rtree_strategy {SELECT * FROM t1 WHERE x1<10}
|
||||
} {Ca}
|
||||
|
||||
do_test rtree6-1.4 {
|
||||
rtree_strategy {SELECT * FROM t1,t2 WHERE k=ii AND x1<10}
|
||||
} {Ca}
|
||||
|
||||
do_test rtree6-1.5 {
|
||||
rtree_strategy {SELECT * FROM t1,t2 WHERE k=+ii AND x1<10}
|
||||
} {Ca}
|
||||
|
||||
do_test rtree6.2.1 {
|
||||
query_plan {SELECT * FROM t1,t2 WHERE k=+ii AND x1<10}
|
||||
} [list \
|
||||
{TABLE t1 VIRTUAL TABLE INDEX 2:Ca} \
|
||||
{TABLE t2 USING PRIMARY KEY} \
|
||||
]
|
||||
|
||||
do_test rtree6.2.2 {
|
||||
query_plan {SELECT * FROM t1,t2 WHERE k=ii AND x1<10}
|
||||
} [list \
|
||||
{TABLE t1 VIRTUAL TABLE INDEX 2:Ca} \
|
||||
{TABLE t2 USING PRIMARY KEY} \
|
||||
]
|
||||
|
||||
do_test rtree6.2.3 {
|
||||
query_plan {SELECT * FROM t1,t2 WHERE k=ii}
|
||||
} [list \
|
||||
{TABLE t2} \
|
||||
{TABLE t1 VIRTUAL TABLE INDEX 1:} \
|
||||
]
|
||||
|
||||
do_test rtree6.2.4 {
|
||||
query_plan {SELECT * FROM t1,t2 WHERE v=10 and x1<10 and x2>10}
|
||||
} [list \
|
||||
{TABLE t2} \
|
||||
{TABLE t1 VIRTUAL TABLE INDEX 2:CaEb} \
|
||||
]
|
||||
|
||||
do_test rtree6.2.5 {
|
||||
query_plan {SELECT * FROM t1,t2 WHERE k=ii AND x1<v}
|
||||
} [list \
|
||||
{TABLE t2} \
|
||||
{TABLE t1 VIRTUAL TABLE INDEX 1:} \
|
||||
]
|
||||
|
||||
finish_test
|
||||
|
15
manifest
15
manifest
@ -1,5 +1,5 @@
|
||||
C Changed\sto\sused\ssqlite3_snprintf\sinstead\sof\ssnprintf\s(test\scode\sonly).\s(CVS\s5648)
|
||||
D 2008-08-31T00:29:08
|
||||
C Have\sthe\srtree\smodule\sset\sthe\sestimatedCost\soutput\svariable.\sTicket\s#3312.\s(CVS\s5649)
|
||||
D 2008-09-01T12:47:00
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in 689e14735f862a5553bceef206d8c13e29504e44
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@ -64,13 +64,14 @@ F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100
|
||||
F ext/icu/README.txt 3b130aa66e7a681136f6add198b076a2f90d1e33
|
||||
F ext/icu/icu.c 12e763d288d23b5a49de37caa30737b971a2f1e2
|
||||
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
|
||||
F ext/rtree/rtree.c d60b28f466cdf4267b237160d75f44365412f3c6
|
||||
F ext/rtree/rtree.c 5e372fdbe572ae8e4e3b4917f048e842dcb57915
|
||||
F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e
|
||||
F ext/rtree/rtree1.test 620223886bf1a319317e63235aac20790375c544
|
||||
F ext/rtree/rtree2.test 9ac9d28fa948779df66916c67a5dcf9704c3cb74
|
||||
F ext/rtree/rtree3.test 877a09c1a0c2b87af0f94f3a286e7dd3b65adf22
|
||||
F ext/rtree/rtree4.test 11724f766a74f48710998cdd7552cec140c55bf9
|
||||
F ext/rtree/rtree5.test 7d0643482829038f0263881ddf7e2d51bff1d60f
|
||||
F ext/rtree/rtree6.test fdfaf62bf026f1312c6eca658979800f3c0bc93f
|
||||
F ext/rtree/rtree_perf.tcl 0fabb6d5c48cb8024e042ce5d4bb88998b6ec1cb
|
||||
F ext/rtree/rtree_util.tcl ee0a0311eb12175319d78bfb37302320496cee6e
|
||||
F ext/rtree/viewrtree.tcl 09526398dae87a5a87c5aac2b3854dbaf8376869
|
||||
@ -627,7 +628,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
P 88c51b9f1579707a8ec394eba61539fabd725e2a
|
||||
R 6475b6bc34459c3a14e2d3b7fca18d08
|
||||
U shane
|
||||
Z cb37c60a6ecfe6b85c8d7118af0df8f4
|
||||
P d68791e35d13f5ae4befeb0bb5f8ccaf14fd3763
|
||||
R cf8a1d32d459a4e4e9a02a25baa421e1
|
||||
U danielk1977
|
||||
Z d770b724d467b2bb63feddfe02dfb4bf
|
||||
|
@ -1 +1 @@
|
||||
d68791e35d13f5ae4befeb0bb5f8ccaf14fd3763
|
||||
483932c4e08901a11b7ab671073fd0a048b10d66
|
Reference in New Issue
Block a user