mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Return SQLITE_ABORT if the underlying shadow tables change in the middle of an rtree query in such a way as to invalidate an rtree internal priority queue entry. This replaces the SQLITE_ABORT_ROLLBACK mechanism added in [af5c4251].
FossilOrigin-Name: 32f85a5ce8e32506ad0cf309c86589958f38d924b4b3de532bec8bdb8e385fad
This commit is contained in:
@ -170,7 +170,6 @@ struct Rtree {
|
|||||||
u32 nBusy; /* Current number of users of this structure */
|
u32 nBusy; /* Current number of users of this structure */
|
||||||
i64 nRowEst; /* Estimated number of rows in this table */
|
i64 nRowEst; /* Estimated number of rows in this table */
|
||||||
u32 nCursor; /* Number of open cursors */
|
u32 nCursor; /* Number of open cursors */
|
||||||
u32 iGeneration; /* Cursors with smaller iGeneration are stale */
|
|
||||||
u32 nNodeRef; /* Number RtreeNodes with positive nRef */
|
u32 nNodeRef; /* Number RtreeNodes with positive nRef */
|
||||||
char *zReadAuxSql; /* SQL for statement to read aux data */
|
char *zReadAuxSql; /* SQL for statement to read aux data */
|
||||||
|
|
||||||
@ -287,7 +286,6 @@ struct RtreeCursor {
|
|||||||
u8 atEOF; /* True if at end of search */
|
u8 atEOF; /* True if at end of search */
|
||||||
u8 bPoint; /* True if sPoint is valid */
|
u8 bPoint; /* True if sPoint is valid */
|
||||||
u8 bAuxValid; /* True if pReadAux is valid */
|
u8 bAuxValid; /* True if pReadAux is valid */
|
||||||
u32 iGeneration; /* Stale if too small */
|
|
||||||
int iStrategy; /* Copy of idxNum search parameter */
|
int iStrategy; /* Copy of idxNum search parameter */
|
||||||
int nConstraint; /* Number of entries in aConstraint */
|
int nConstraint; /* Number of entries in aConstraint */
|
||||||
RtreeConstraint *aConstraint; /* Search constraints. */
|
RtreeConstraint *aConstraint; /* Search constraints. */
|
||||||
@ -948,6 +946,7 @@ static void nodeGetCoord(
|
|||||||
int iCoord, /* Which coordinate to extract */
|
int iCoord, /* Which coordinate to extract */
|
||||||
RtreeCoord *pCoord /* OUT: Space to write result to */
|
RtreeCoord *pCoord /* OUT: Space to write result to */
|
||||||
){
|
){
|
||||||
|
assert( iCell<NCELL(pNode) );
|
||||||
readCoord(&pNode->zData[12 + pRtree->nBytesPerCell*iCell + 4*iCoord], pCoord);
|
readCoord(&pNode->zData[12 + pRtree->nBytesPerCell*iCell + 4*iCoord], pCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1089,7 +1088,6 @@ static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
|
|||||||
if( pCsr ){
|
if( pCsr ){
|
||||||
memset(pCsr, 0, sizeof(RtreeCursor));
|
memset(pCsr, 0, sizeof(RtreeCursor));
|
||||||
pCsr->base.pVtab = pVTab;
|
pCsr->base.pVtab = pVTab;
|
||||||
pCsr->iGeneration = pRtree->iGeneration;
|
|
||||||
rc = SQLITE_OK;
|
rc = SQLITE_OK;
|
||||||
pRtree->nCursor++;
|
pRtree->nCursor++;
|
||||||
}
|
}
|
||||||
@ -1630,9 +1628,6 @@ static int rtreeStepToLeaf(RtreeCursor *pCur){
|
|||||||
int eInt;
|
int eInt;
|
||||||
RtreeSearchPoint x;
|
RtreeSearchPoint x;
|
||||||
|
|
||||||
if( pCur->iGeneration<pRtree->iGeneration ){
|
|
||||||
return SQLITE_ABORT_ROLLBACK;
|
|
||||||
}
|
|
||||||
eInt = pRtree->eCoordType==RTREE_COORD_INT32;
|
eInt = pRtree->eCoordType==RTREE_COORD_INT32;
|
||||||
while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){
|
while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){
|
||||||
u8 *pCellData;
|
u8 *pCellData;
|
||||||
@ -1726,7 +1721,11 @@ static int rtreeRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *pRowid){
|
|||||||
int rc = SQLITE_OK;
|
int rc = SQLITE_OK;
|
||||||
RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
|
RtreeNode *pNode = rtreeNodeOfFirstSearchPoint(pCsr, &rc);
|
||||||
if( rc==SQLITE_OK && ALWAYS(p) ){
|
if( rc==SQLITE_OK && ALWAYS(p) ){
|
||||||
*pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell);
|
if( p->iCell>=NCELL(pNode) ){
|
||||||
|
rc = SQLITE_ABORT;
|
||||||
|
}else{
|
||||||
|
*pRowid = nodeGetRowid(RTREE_OF_CURSOR(pCsr), pNode, p->iCell);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -1744,6 +1743,7 @@ static int rtreeColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
|
|||||||
|
|
||||||
if( rc ) return rc;
|
if( rc ) return rc;
|
||||||
if( NEVER(p==0) ) return SQLITE_OK;
|
if( NEVER(p==0) ) return SQLITE_OK;
|
||||||
|
if( p->iCell>=NCELL(pNode) ) return SQLITE_ABORT;
|
||||||
if( i==0 ){
|
if( i==0 ){
|
||||||
sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
|
sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
|
||||||
}else if( i<=pRtree->nDim2 ){
|
}else if( i<=pRtree->nDim2 ){
|
||||||
@ -1860,7 +1860,6 @@ static int rtreeFilter(
|
|||||||
|
|
||||||
/* Reset the cursor to the same state as rtreeOpen() leaves it in. */
|
/* Reset the cursor to the same state as rtreeOpen() leaves it in. */
|
||||||
resetCursor(pCsr);
|
resetCursor(pCsr);
|
||||||
pCsr->iGeneration = pRtree->iGeneration;
|
|
||||||
|
|
||||||
pCsr->iStrategy = idxNum;
|
pCsr->iStrategy = idxNum;
|
||||||
if( idxNum==1 ){
|
if( idxNum==1 ){
|
||||||
@ -3242,15 +3241,8 @@ static int rtreeEndTransaction(sqlite3_vtab *pVtab){
|
|||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
static int rtreeRollback(sqlite3_vtab *pVtab){
|
static int rtreeRollback(sqlite3_vtab *pVtab){
|
||||||
Rtree *pRtree = (Rtree *)pVtab;
|
|
||||||
pRtree->iGeneration++;
|
|
||||||
return rtreeEndTransaction(pVtab);
|
return rtreeEndTransaction(pVtab);
|
||||||
}
|
}
|
||||||
static int rtreeRollbackTo(sqlite3_vtab *pVtab, int notUsed){
|
|
||||||
Rtree *pRtree = (Rtree *)pVtab;
|
|
||||||
pRtree->iGeneration++;
|
|
||||||
return SQLITE_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** The xRename method for rtree module virtual tables.
|
** The xRename method for rtree module virtual tables.
|
||||||
@ -3374,7 +3366,7 @@ static sqlite3_module rtreeModule = {
|
|||||||
rtreeRename, /* xRename - rename the table */
|
rtreeRename, /* xRename - rename the table */
|
||||||
rtreeSavepoint, /* xSavepoint */
|
rtreeSavepoint, /* xSavepoint */
|
||||||
0, /* xRelease */
|
0, /* xRelease */
|
||||||
rtreeRollbackTo, /* xRollbackTo */
|
0, /* xRollbackTo */
|
||||||
rtreeShadowName, /* xShadowName */
|
rtreeShadowName, /* xShadowName */
|
||||||
rtreeIntegrity /* xIntegrity */
|
rtreeIntegrity /* xIntegrity */
|
||||||
};
|
};
|
||||||
|
@ -44,7 +44,7 @@ do_test 1.2 {
|
|||||||
}
|
}
|
||||||
} msg]
|
} msg]
|
||||||
list $rc $msg
|
list $rc $msg
|
||||||
} {1 {abort due to ROLLBACK}}
|
} {1 {query aborted}}
|
||||||
|
|
||||||
do_execsql_test 1.3 {
|
do_execsql_test 1.3 {
|
||||||
SELECT * FROM t1;
|
SELECT * FROM t1;
|
||||||
@ -118,7 +118,7 @@ do_test 1.8 {
|
|||||||
}
|
}
|
||||||
} msg]
|
} msg]
|
||||||
list $rc $msg
|
list $rc $msg
|
||||||
} {1 {abort due to ROLLBACK}}
|
} {1 {query aborted}}
|
||||||
|
|
||||||
do_execsql_test 1.9 {
|
do_execsql_test 1.9 {
|
||||||
COMMIT;
|
COMMIT;
|
||||||
@ -156,4 +156,117 @@ do_execsql_test 1.12 {
|
|||||||
SELECT * FROM t1;
|
SELECT * FROM t1;
|
||||||
} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0}
|
} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
reset_db
|
||||||
|
do_execsql_test 2.0 {
|
||||||
|
CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2);
|
||||||
|
INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2);
|
||||||
|
CREATE TABLE t2(x);
|
||||||
|
} {}
|
||||||
|
|
||||||
|
do_test 2.1 {
|
||||||
|
db eval {
|
||||||
|
BEGIN;
|
||||||
|
INSERT INTO t1 VALUES(3, 3, 3);
|
||||||
|
PRAGMA writable_schema = RESET;
|
||||||
|
}
|
||||||
|
|
||||||
|
set rc [catch {
|
||||||
|
db eval { SELECT x1, x2 FROM t1 } {
|
||||||
|
if {$x1==1} {
|
||||||
|
db eval { ROLLBACK }
|
||||||
|
}
|
||||||
|
lappend res $x1 $x2
|
||||||
|
}
|
||||||
|
} msg]
|
||||||
|
list $rc $msg
|
||||||
|
} {1 {query aborted}}
|
||||||
|
|
||||||
|
do_execsql_test 2.1 {
|
||||||
|
CREATE TABLE bak_node(nodeno, data);
|
||||||
|
CREATE TABLE bak_parent(nodeno, parentnode);
|
||||||
|
CREATE TABLE bak_rowid(rowid, nodeno);
|
||||||
|
}
|
||||||
|
proc save_t1 {} {
|
||||||
|
db eval {
|
||||||
|
DELETE FROM bak_node;
|
||||||
|
DELETE FROM bak_parent;
|
||||||
|
DELETE FROM bak_rowid;
|
||||||
|
INSERT INTO bak_node SELECT * FROM t1_node;
|
||||||
|
INSERT INTO bak_parent SELECT * FROM t1_parent;
|
||||||
|
INSERT INTO bak_rowid SELECT * FROM t1_rowid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
proc restore_t1 {} {
|
||||||
|
db eval {
|
||||||
|
DELETE FROM t1_node;
|
||||||
|
DELETE FROM t1_parent;
|
||||||
|
DELETE FROM t1_rowid;
|
||||||
|
INSERT INTO t1_node SELECT * FROM bak_node;
|
||||||
|
INSERT INTO t1_parent SELECT * FROM bak_parent;
|
||||||
|
INSERT INTO t1_rowid SELECT * FROM bak_rowid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
do_test 2.3 {
|
||||||
|
save_t1
|
||||||
|
db eval {
|
||||||
|
INSERT INTO t1 VALUES(3, 3, 3);
|
||||||
|
}
|
||||||
|
set rc [catch {
|
||||||
|
db eval { SELECT rowid, x1, x2 FROM t1 } {
|
||||||
|
if {$x1==1} {
|
||||||
|
restore_t1
|
||||||
|
}
|
||||||
|
lappend res $x1 $x2
|
||||||
|
}
|
||||||
|
} msg]
|
||||||
|
list $rc $msg
|
||||||
|
} {1 {query aborted}}
|
||||||
|
do_execsql_test 2.4 {
|
||||||
|
SELECT * FROM t1
|
||||||
|
} {1 1.0 1.0 2 2.0 2.0}
|
||||||
|
|
||||||
|
do_test 2.5 {
|
||||||
|
save_t1
|
||||||
|
db eval {
|
||||||
|
INSERT INTO t1 VALUES(3, 3, 3);
|
||||||
|
}
|
||||||
|
set rc [catch {
|
||||||
|
db eval { SELECT x1 FROM t1 } {
|
||||||
|
if {$x1==1} {
|
||||||
|
restore_t1
|
||||||
|
}
|
||||||
|
lappend res $x1 $x2
|
||||||
|
}
|
||||||
|
} msg]
|
||||||
|
list $rc $msg
|
||||||
|
} {1 {query aborted}}
|
||||||
|
do_execsql_test 2.6 {
|
||||||
|
SELECT * FROM t1
|
||||||
|
} {1 1.0 1.0 2 2.0 2.0}
|
||||||
|
|
||||||
|
do_test 2.7 {
|
||||||
|
save_t1
|
||||||
|
db eval {
|
||||||
|
INSERT INTO t1 VALUES(3, 3, 3);
|
||||||
|
}
|
||||||
|
set ::res [list]
|
||||||
|
set rc [catch {
|
||||||
|
db eval { SELECT 'abc' FROM t1 } {
|
||||||
|
if {$::res==[list]} {
|
||||||
|
restore_t1
|
||||||
|
set ::bDone 1
|
||||||
|
}
|
||||||
|
lappend res abc
|
||||||
|
}
|
||||||
|
} msg]
|
||||||
|
set res
|
||||||
|
} {abc abc abc}
|
||||||
|
do_execsql_test 2.6 {
|
||||||
|
SELECT * FROM t1
|
||||||
|
} {1 1.0 1.0 2 2.0 2.0}
|
||||||
|
|
||||||
|
|
||||||
finish_test
|
finish_test
|
||||||
|
17
manifest
17
manifest
@ -1,5 +1,5 @@
|
|||||||
C Extend\s[d294a23ed6d]\sto\sapply\sto\sall\swasm\sspeedtest1\sbuilds.
|
C Return\sSQLITE_ABORT\sif\sthe\sunderlying\sshadow\stables\schange\sin\sthe\smiddle\sof\san\srtree\squery\sin\ssuch\sa\sway\sas\sto\sinvalidate\san\srtree\sinternal\spriority\squeue\sentry.\sThis\sreplaces\sthe\sSQLITE_ABORT_ROLLBACK\smechanism\sadded\sin\s[af5c4251].
|
||||||
D 2024-02-05T03:56:02.476
|
D 2024-02-05T17:54:03.662
|
||||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||||
@ -495,7 +495,7 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350
|
|||||||
F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c
|
F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c
|
||||||
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
|
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
|
||||||
F ext/rtree/geopoly.c 0dd4775e896cee6067979d67aff7c998e75c2c9d9cd8d62a1a790c09cde7adca
|
F ext/rtree/geopoly.c 0dd4775e896cee6067979d67aff7c998e75c2c9d9cd8d62a1a790c09cde7adca
|
||||||
F ext/rtree/rtree.c 32e67b122e37138694d9f499cdc72241e372058560ac2d4577cfd68ccd692953
|
F ext/rtree/rtree.c 920884cfeb88e8a77ef23d70bc696c1a59f2de03b8e877c0966ae81ea61aa41a
|
||||||
F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412
|
F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412
|
||||||
F ext/rtree/rtree1.test 2b5b8c719c6a4abe377f57766f428a49af36a93061cb146cccfdc3b30000c0a4
|
F ext/rtree/rtree1.test 2b5b8c719c6a4abe377f57766f428a49af36a93061cb146cccfdc3b30000c0a4
|
||||||
F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d
|
F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d
|
||||||
@ -515,7 +515,7 @@ F ext/rtree/rtreeF.test 81ffa7ef51c4e4618d497a57328c265bf576990c7070633b623b23cd
|
|||||||
F ext/rtree/rtreeG.test 1b9ca6e3effb48f4161edaa463ddeaa8fca4b2526d084f9cbf5dbe4e0184939c
|
F ext/rtree/rtreeG.test 1b9ca6e3effb48f4161edaa463ddeaa8fca4b2526d084f9cbf5dbe4e0184939c
|
||||||
F ext/rtree/rtreeH.test 0885151ee8429242625600ae47142cca935332c70a06737f35af53a7bd7aaf90
|
F ext/rtree/rtreeH.test 0885151ee8429242625600ae47142cca935332c70a06737f35af53a7bd7aaf90
|
||||||
F ext/rtree/rtreeI.test 608e77f7fde9be5a12eae316baef640fffaafcfa90a3d67443e78123e19c4ca4
|
F ext/rtree/rtreeI.test 608e77f7fde9be5a12eae316baef640fffaafcfa90a3d67443e78123e19c4ca4
|
||||||
F ext/rtree/rtreeJ.test bafa7616d6b29448bf19132ce4963a69b629b9ca6ab29f4b76889c8d542b8dfc
|
F ext/rtree/rtreeJ.test ba4e25c409ebed4b96bf1270e72760c1344d0a464478d221dbe91e8471ac9ac6
|
||||||
F ext/rtree/rtree_perf.tcl 6c18c1f23cd48e0f948930c98dfdd37dfccb5195
|
F ext/rtree/rtree_perf.tcl 6c18c1f23cd48e0f948930c98dfdd37dfccb5195
|
||||||
F ext/rtree/rtree_util.tcl 202ca70df1f0645ef9d5a2170e62d378a28098d9407f0569e85c9c1cf1bd020a
|
F ext/rtree/rtree_util.tcl 202ca70df1f0645ef9d5a2170e62d378a28098d9407f0569e85c9c1cf1bd020a
|
||||||
F ext/rtree/rtreecheck.test 934546ad9b563e090ee0c5cbdc69ad014189ad76e5df7320526797a9a345661f
|
F ext/rtree/rtreecheck.test 934546ad9b563e090ee0c5cbdc69ad014189ad76e5df7320526797a9a345661f
|
||||||
@ -2162,8 +2162,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
|||||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||||
P f8a8b9ee2eddf5f875c7c4399e750ccf1941f767560ebc2c88c083560f5aaae0
|
P 26f848e5e0ac34e545d2f27cf33abc46eac13e04ed9cd71084b0f7d47136ff97 478280ef67efed854988ab4f740a38ae1937204c0434ad8da11f1869a12a6d06
|
||||||
R 8054a7da52bc11a97b67caaa9fc96227
|
R 23677f173f1ac581895d1554488f83a5
|
||||||
U stephan
|
T +closed 478280ef67efed854988ab4f740a38ae1937204c0434ad8da11f1869a12a6d06
|
||||||
Z 47b7f55b1ab54c273898a455c5270730
|
U dan
|
||||||
|
Z 1c1abeb44ec4a55c053a1bd1e00c844a
|
||||||
# Remove this line to create a well-formed Fossil manifest.
|
# Remove this line to create a well-formed Fossil manifest.
|
||||||
|
@ -1 +1 @@
|
|||||||
26f848e5e0ac34e545d2f27cf33abc46eac13e04ed9cd71084b0f7d47136ff97
|
32f85a5ce8e32506ad0cf309c86589958f38d924b4b3de532bec8bdb8e385fad
|
Reference in New Issue
Block a user