From: dan Date: Tue, 18 Jul 2017 19:51:11 +0000 (+0000) Subject: Have unionvtab support constraints on the column that corresponds to the X-Git-Tag: version-3.20.0~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=090f68a39057f0d826cbd33f60672f2517c8ec38;p=thirdparty%2Fsqlite.git Have unionvtab support constraints on the column that corresponds to the INTEGER PRIMARY KEY field of the underlying source tables in the same way as rowid. FossilOrigin-Name: 4a6c416fa025a34116ea30923a673cbb108b251b2676734ec8f603600e38e50e --- diff --git a/ext/misc/unionvtab.c b/ext/misc/unionvtab.c index 23b66f8125..d309d8e4ac 100644 --- a/ext/misc/unionvtab.c +++ b/ext/misc/unionvtab.c @@ -87,6 +87,7 @@ struct UnionSrc { struct UnionTab { sqlite3_vtab base; /* Base class - must be first */ sqlite3 *db; /* Database handle */ + int iPK; /* INTEGER PRIMARY KEY column, or -1 */ int nSrc; /* Number of elements in the aSrc[] array */ UnionSrc *aSrc; /* Array of source tables, sorted by rowid */ }; @@ -458,19 +459,18 @@ static int unionConnect( zSql = sqlite3_mprintf("SELECT " "'CREATE TABLE xyz('" " || group_concat(quote(name) || ' ' || type, ', ')" - " || ')'" + " || ')'," + "max((cid+1) * (type='INTEGER' COLLATE nocase AND pk=1))-1 " "FROM pragma_table_info(%Q, ?)", - pTab->aSrc[0].zTab + pTab->aSrc[0].zTab, pTab->aSrc[0].zDb ); if( zSql==0 ) rc = SQLITE_NOMEM; } pStmt = unionPrepare(&rc, db, zSql, pzErr); - if( rc==SQLITE_OK ){ - sqlite3_bind_text(pStmt, 1, pTab->aSrc[0].zDb, -1, SQLITE_STATIC); - if( SQLITE_ROW==sqlite3_step(pStmt) ){ - const char *zDecl = (const char*)sqlite3_column_text(pStmt, 0); - rc = sqlite3_declare_vtab(db, zDecl); - } + if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ + const char *zDecl = (const char*)sqlite3_column_text(pStmt, 0); + rc = sqlite3_declare_vtab(db, zDecl); + pTab->iPK = sqlite3_column_int(pStmt, 1); } unionFinalize(&rc, pStmt); @@ -686,6 +686,7 @@ static int unionBestIndex( sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo ){ + UnionTab *pTab = (UnionTab*)tab; int iEq = -1; int iLt = -1; int iGt = -1; @@ -693,7 +694,7 @@ static int unionBestIndex( for(i=0; inConstraint; i++){ struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[i]; - if( p->usable && p->iColumn<0 ){ + if( p->usable && (p->iColumn<0 || p->iColumn==pTab->iPK) ){ switch( p->op ){ case SQLITE_INDEX_CONSTRAINT_EQ: if( iEq<0 ) iEq = i; diff --git a/manifest b/manifest index 1603d45d57..2b29cef9a2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stest\scases\sto\sunionvtab.test. -D 2017-07-18T18:50:37.772 +C Have\sunionvtab\ssupport\sconstraints\son\sthe\scolumn\sthat\scorresponds\sto\sthe\nINTEGER\sPRIMARY\sKEY\sfield\sof\sthe\sunderlying\ssource\stables\sin\sthe\ssame\sway\sas\nrowid. +D 2017-07-18T19:51:11.061 F Makefile.in d9873c9925917cca9990ee24be17eb9613a668012c85a343aef7e5536ae266e8 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 20850e3e8d4d4791e0531955852d768eb06f24138214870d543abb1a47346fba @@ -281,7 +281,7 @@ F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 F ext/misc/spellfix.c a4723b6aff748a417b5091b68a46443265c40f0d F ext/misc/stmt.c 6f16443abb3551e3f5813bb13ba19a30e7032830015b0f92fe0c0453045c0a11 F ext/misc/totype.c 4a167594e791abeed95e0a8db028822b5e8fe512 -F ext/misc/unionvtab.c cd5fbb09581e4d750c70b338cf9b68cd43889fc40419895ba59887b717c11933 +F ext/misc/unionvtab.c 2ee97a136cc300fe17c9591015ae2ee4eea2a78458e46dd44550e0a441a091ff F ext/misc/vfslog.c fe40fab5c077a40477f7e5eba994309ecac6cc95 F ext/misc/vfsstat.c bf10ef0bc51e1ad6756629e1edb142f7a8db1178 F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd @@ -1432,7 +1432,7 @@ F test/tt3_vacuum.c 1753f45917699c9c1f66b64c717a717c9379f776 F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff F test/types2.test 1aeb81976841a91eef292723649b5c4fe3bc3cac F test/types3.test 99e009491a54f4dc02c06bdbc0c5eea56ae3e25a -F test/unionvtab.test fff214df907bbe830f5637d672b6ef945010e1375de1186083de80da84583c40 +F test/unionvtab.test 4f99277e18a23cb29375b03ce74dcac525bef10cea00c2bc502d8bc6d761feb9 F test/unique.test 93f8b2ef5ea51b9495f8d6493429b1fd0f465264 F test/unique2.test 3674e9f2a3f1fbbfd4772ac74b7a97090d0f77d2 F test/unixexcl.test d936ba2b06794018e136418addd59a2354eeae97 @@ -1635,7 +1635,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 948f95046b7eaa8c68617b36625a7500dd0e69e52425ac6d748f2a311eb2474a -R 6fc81d1e1254a0fa7b9a54d980f776e3 +P 6c9128e1a53f8cf26de9ef1bc07051f2c94287531edacfcfb69d3cd7590240b3 +R dc8f15610e867937249e25b515a6a200 U dan -Z 0fa121be6f0cc20896dfe2962de52055 +Z 6262d0cb27792cd399228e6052fa5f80 diff --git a/manifest.uuid b/manifest.uuid index 7db3ba5f25..6fc68db875 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6c9128e1a53f8cf26de9ef1bc07051f2c94287531edacfcfb69d3cd7590240b3 \ No newline at end of file +4a6c416fa025a34116ea30923a673cbb108b251b2676734ec8f603600e38e50e \ No newline at end of file diff --git a/test/unionvtab.test b/test/unionvtab.test index f39466457f..c472dfadf5 100644 --- a/test/unionvtab.test +++ b/test/unionvtab.test @@ -251,6 +251,18 @@ do_execsql_test 3.9.2 { SELECT count(*) FROM uu WHERE rowid > $L } {0} do_execsql_test 3.9.3 { SELECT count(*) FROM uu WHERE rowid <= $L } {300} do_execsql_test 3.9.4 { SELECT count(*) FROM uu WHERE rowid < $L } {300} +do_execsql_test 3.10.1 { SELECT count(*) FROM uu WHERE a < 25 } {24} +do_execsql_test 3.10.2 { SELECT count(*) FROM uu WHERE a < 26 } {100} +do_execsql_test 3.10.3 { SELECT count(*) FROM uu WHERE a < 27 } {126} +do_execsql_test 3.10.4 { SELECT count(*) FROM uu WHERE a < 73 } {172} +do_execsql_test 3.10.5 { SELECT count(*) FROM uu WHERE a < 74 } {173} +do_execsql_test 3.10.6 { SELECT count(*) FROM uu WHERE a < 75 } {200} +do_execsql_test 3.10.7 { SELECT count(*) FROM uu WHERE a < 76 } {275} +do_execsql_test 3.10.8 { SELECT count(*) FROM uu WHERE a < 99 } {298} +do_execsql_test 3.10.9 { SELECT count(*) FROM uu WHERE a < 100 } {299} +do_execsql_test 3.10.10 { SELECT count(*) FROM uu WHERE a < 101 } {300} + + #------------------------------------------------------------------------- # do_execsql_test 4.0 {