mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Fix the WITHOUT ROWID table logic so that it generates a correct KeyInfo
object for tables that have a PRIMARY KEY containing the same column used more than once with different collating sequences. Enhance the index_xinfo pragma to assist in testing the above. Fix for ticket [fd3aec0c7e3e2998]. FossilOrigin-Name: 84a51a755c18ac8253080db6eec505df894ee3b1e97cfa8e61039ac38001e270
This commit is contained in:
24
manifest
24
manifest
@@ -1,5 +1,5 @@
|
||||
C Add\scasts\sto\sshell.c.in\sto\savoid\swarnings\son\ssystems\swhere\ssize_t\sis\s32\sbits.
|
||||
D 2019-07-17T07:23:06.341
|
||||
C Fix\sthe\sWITHOUT\sROWID\stable\slogic\sso\sthat\sit\sgenerates\sa\scorrect\sKeyInfo\nobject\sfor\stables\sthat\shave\sa\sPRIMARY\sKEY\scontaining\sthe\ssame\scolumn\sused\nmore\sthan\sonce\swith\sdifferent\scollating\ssequences.\s\sEnhance\sthe\sindex_xinfo\npragma\sto\sassist\sin\stesting\sthe\sabove.\sFix\sfor\sticket\s[fd3aec0c7e3e2998].
|
||||
D 2019-07-17T12:49:16.424
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@@ -466,7 +466,7 @@ F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
|
||||
F src/btree.c 83a4b1b744fad3ff675f68bc4de73834ed0e31edb412097f54e33cf181bba1ee
|
||||
F src/btree.h c11446f07ec0e9dc85af8041cb0855c52f5359c8b2a43e47e02a685282504d89
|
||||
F src/btreeInt.h 6111c15868b90669f79081039d19e7ea8674013f907710baa3c814dc3f8bfd3f
|
||||
F src/build.c cd19eb05c63ccaeee5e659e6e708a97d905b62f639de71af0c2c007062371a75
|
||||
F src/build.c 48f22e7c3b80550eb9c0cc3a3738f9117109b87d5f5fdba027009b7f2917df4a
|
||||
F src/callback.c 25dda5e1c2334a367b94a64077b1d06b2553369f616261ca6783c48bcb6bda73
|
||||
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
|
||||
F src/ctime.c 37f3d21193c4f7d141d0691cced5b39c99951bfef78df9887faf9167b9c42f37
|
||||
@@ -515,7 +515,7 @@ F src/parse.y 22889d25bbab20b3fbff5eca1208a1f098ce9cf3ebc309f0dd0753dda79cc864
|
||||
F src/pcache.c 385ff064bca69789d199a98e2169445dc16e4291fa807babd61d4890c3b34177
|
||||
F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586
|
||||
F src/pcache1.c 62714cbd1b7299a6e6a27a587b66b4fd3a836a84e1181e7f96f5c34a50917848
|
||||
F src/pragma.c 925bcac0afd98a0d4255c7524b93239ab4d83893d96f7f8fdccd78d4929a39bb
|
||||
F src/pragma.c a42d4c6040893a59b69a0c987e5ed0402730c444ee451fde9bbe6203e7f73b1d
|
||||
F src/pragma.h 4a9fabff14db4487a734dfeeb4be984ce662bfdccfae16145b9c732327735e13
|
||||
F src/prepare.c 1fdf68a8add154bd1de978dde5a4819478e2576d5701b93db2c65d78c3daf1c8
|
||||
F src/printf.c 9be6945837c839ba57837b4bc3af349eba630920fa5532aa518816defe42a7d4
|
||||
@@ -1610,7 +1610,7 @@ F test/vacuummem.test 7b42abb3208bd82dd23a7536588396f295a314f2
|
||||
F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62
|
||||
F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661
|
||||
F test/view.test 40d54c9ddf5b9fdee692bf936d3352159fe467838f92742aa1d08c7c7d1eac73
|
||||
F test/vtab1.test 47b935205d7b6290765973abd6fce0e13e94e040017099170f43f81886efa5ba
|
||||
F test/vtab1.test fa6baded08fdadd6f416a9c54956c049ae327b9bdd05d25bf8163f65e65e849c
|
||||
F test/vtab2.test 14d4ab26cee13ba6cf5c5601b158e4f57552d3b055cdd9406cf7f711e9c84082
|
||||
F test/vtab3.test b45f47d20f225ccc9c28dc915d92740c2dee311e
|
||||
F test/vtab4.test 8e73ed268f3d596bc3590f45fc948fb40f28e9c3
|
||||
@@ -1721,12 +1721,13 @@ F test/with2.test e0030e2f0267a910d6c0e4f46f2dfe941c1cc0d4f659ba69b3597728e7e8f1
|
||||
F test/with3.test b5f1372097690c6ef84db2f13fc7e64a88c7263c3f88493605f90597e8a68d45
|
||||
F test/with4.test 257be66c0c67fee1defbbac0f685c3465e2cad037f21ce65f23f86084f198205
|
||||
F test/withM.test 693b61765f2b387b5e3e24a4536e2e82de15ff64
|
||||
F test/without_rowid1.test 89d101a7c6e0802882002cf3713f405319ddb6b9f08449dcc08c6082c995cab1
|
||||
F test/without_rowid1.test edfccaea4c7d15d9f8ca1c6d7e58df5a7e64969140bcb4598a95edfe1bfd7e7e
|
||||
F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99
|
||||
F test/without_rowid3.test ea4b59dd1b0d7f5f5e4b7cca978cdb905752a9d7c57dc4344a591dba765a3691
|
||||
F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a
|
||||
F test/without_rowid5.test 89b1c587bd92a0590e440da33e7666bf4891572a
|
||||
F test/without_rowid6.test 1f99644e6508447fb050f73697350c7ceca3392e
|
||||
F test/without_rowid6.test 3c1bbf0eb81c672115933158b62b009e67cf1a7f8c2c612bbce63a7385efa18e
|
||||
F test/without_rowid7.test 0e0d7be00f05f54898e20e07bcc947cd97b42d7106021fa0d2897324bc6d330e
|
||||
F test/wordcount.c d721a4b6fae93e6e33449700bce1686bc23257c27425bc3ef1599dc912adec66
|
||||
F test/writecrash.test f1da7f7adfe8d7f09ea79b42e5ca6dcc41102f27f8e334ad71539501ddd910cc
|
||||
F test/zeroblob.test 07a5b11ab591d1f26c626945fb7f228f68b993533b2ada77273edf6ee29db174
|
||||
@@ -1835,7 +1836,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 9e66458592d40fbd96ea5f21339573110ca1cfe328238a020c9420a87d35dd72
|
||||
R e10a56ffab89aeb6c132764d41933ce5
|
||||
U dan
|
||||
Z 0a446b49c5cd11f0249e04708e61ac08
|
||||
P fe014288ac03cdf0dc5410b7d45cad4768759b52746c0a22bce2fc03779c5d5a 340378c1e60da80263523776f4b6366a9d332a7ee25986637e8b157f4e8e4bd3
|
||||
R 5f5f2ffbc62c0e7052c26dec78f9d9ee
|
||||
T +closed 340378c1e60da80263523776f4b6366a9d332a7ee25986637e8b157f4e8e4bd3
|
||||
U drh
|
||||
Z a8a117274901c94c5f21fbb39eeada13
|
||||
|
@@ -1 +1 @@
|
||||
fe014288ac03cdf0dc5410b7d45cad4768759b52746c0a22bce2fc03779c5d5a
|
||||
84a51a755c18ac8253080db6eec505df894ee3b1e97cfa8e61039ac38001e270
|
34
src/build.c
34
src/build.c
@@ -1831,6 +1831,7 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
Index *pIdx;
|
||||
Index *pPk;
|
||||
int nPk;
|
||||
int nExtra;
|
||||
int i, j;
|
||||
sqlite3 *db = pParse->db;
|
||||
Vdbe *v = pParse->pVdbe;
|
||||
@@ -1873,6 +1874,7 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
SQLITE_IDXTYPE_PRIMARYKEY);
|
||||
if( db->mallocFailed || pParse->nErr ) return;
|
||||
pPk = sqlite3PrimaryKeyIndex(pTab);
|
||||
assert( pPk->nKeyCol==1 );
|
||||
}else{
|
||||
pPk = sqlite3PrimaryKeyIndex(pTab);
|
||||
assert( pPk!=0 );
|
||||
@@ -1887,6 +1889,8 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
pPk->nColumn--;
|
||||
}else{
|
||||
testcase( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) );
|
||||
pPk->azColl[j] = pPk->azColl[i];
|
||||
pPk->aSortOrder[j] = pPk->aSortOrder[i];
|
||||
pPk->aiColumn[j++] = pPk->aiColumn[i];
|
||||
}
|
||||
}
|
||||
@@ -1895,7 +1899,7 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
assert( pPk!=0 );
|
||||
pPk->isCovering = 1;
|
||||
if( !db->init.imposterTable ) pPk->uniqNotNull = 1;
|
||||
nPk = pPk->nKeyCol;
|
||||
nPk = pPk->nColumn = pPk->nKeyCol;
|
||||
|
||||
/* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
|
||||
** table entry. This is only required if currently generating VDBE
|
||||
@@ -1945,21 +1949,21 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
|
||||
/* Add all table columns to the PRIMARY KEY index
|
||||
*/
|
||||
if( nPk<pTab->nCol ){
|
||||
if( resizeIndexObject(db, pPk, pTab->nCol) ) return;
|
||||
for(i=0, j=nPk; i<pTab->nCol; i++){
|
||||
if( !hasColumn(pPk->aiColumn, j, i) ){
|
||||
assert( j<pPk->nColumn );
|
||||
pPk->aiColumn[j] = i;
|
||||
pPk->azColl[j] = sqlite3StrBINARY;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
assert( pPk->nColumn==j );
|
||||
assert( pTab->nCol==j );
|
||||
}else{
|
||||
pPk->nColumn = pTab->nCol;
|
||||
nExtra = 0;
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( !hasColumn(pPk->aiColumn, nPk, i) ) nExtra++;
|
||||
}
|
||||
if( resizeIndexObject(db, pPk, nPk+nExtra) ) return;
|
||||
for(i=0, j=nPk; i<pTab->nCol; i++){
|
||||
if( !hasColumn(pPk->aiColumn, j, i) ){
|
||||
assert( j<pPk->nColumn );
|
||||
pPk->aiColumn[j] = i;
|
||||
pPk->azColl[j] = sqlite3StrBINARY;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
assert( pPk->nColumn==j );
|
||||
assert( pTab->nCol<=j );
|
||||
recomputeColumnsNotIndexed(pPk);
|
||||
}
|
||||
|
||||
|
@@ -1157,6 +1157,15 @@ void sqlite3Pragma(
|
||||
Index *pIdx;
|
||||
Table *pTab;
|
||||
pIdx = sqlite3FindIndex(db, zRight, zDb);
|
||||
if( pIdx==0 ){
|
||||
/* If there is no index named zRight, check to see if there is a
|
||||
** WITHOUT ROWID table named zRight, and if there is, show the
|
||||
** structure of the PRIMARY KEY index for that table. */
|
||||
pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb);
|
||||
if( pTab && !HasRowid(pTab) ){
|
||||
pIdx = sqlite3PrimaryKeyIndex(pTab);
|
||||
}
|
||||
}
|
||||
if( pIdx ){
|
||||
int iIdxDb = sqlite3SchemaToIndex(db, pIdx->pSchema);
|
||||
int i;
|
||||
|
@@ -875,6 +875,14 @@ do_test vtab1.7-13 {
|
||||
}
|
||||
} {}
|
||||
|
||||
# PRAGMA index_info and index_xinfo are no-ops on a virtual table
|
||||
do_test vtab1.7-14 {
|
||||
execsql {
|
||||
PRAGMA index_info('echo_abc');
|
||||
PRAGMA index_xinfo('echo_abc');
|
||||
}
|
||||
} {}
|
||||
|
||||
ifcapable attach {
|
||||
do_test vtab1.8-1 {
|
||||
set echo_module ""
|
||||
|
@@ -31,6 +31,10 @@ do_execsql_test without_rowid1-1.0 {
|
||||
|
||||
integrity_check without_rowid1-1.0ic
|
||||
|
||||
do_execsql_test without_rowid1-1.0ixi {
|
||||
SELECT name, key FROM pragma_index_xinfo('t1');
|
||||
} {c 1 a 1 b 0 d 0}
|
||||
|
||||
do_execsql_test without_rowid1-1.1 {
|
||||
SELECT *, '|' FROM t1 ORDER BY +c, a;
|
||||
} {arctic sleep ammonia helena | journal sherman ammonia helena | dynamic juliet flipper command | journal sherman gamma patriot |}
|
||||
@@ -120,6 +124,9 @@ do_execsql_test 2.1.2 {
|
||||
UPDATE t4 SET a = 'ABC';
|
||||
SELECT * FROM t4;
|
||||
} {ABC def}
|
||||
do_execsql_test 2.1.3 {
|
||||
SELECT name, coll, key FROM pragma_index_xinfo('t4');
|
||||
} {a nocase 1 b BINARY 0}
|
||||
|
||||
do_execsql_test 2.2.1 {
|
||||
DROP TABLE t4;
|
||||
@@ -133,12 +140,22 @@ do_execsql_test 2.2.2 {
|
||||
SELECT * FROM t4;
|
||||
} {xyz ABC}
|
||||
|
||||
do_execsql_test 2.2.3 {
|
||||
SELECT name, coll, key FROM pragma_index_xinfo('t4');
|
||||
} {a nocase 1 b BINARY 0}
|
||||
|
||||
|
||||
do_execsql_test 2.3.1 {
|
||||
CREATE TABLE t5 (a, b, PRIMARY KEY(b, a)) WITHOUT ROWID;
|
||||
INSERT INTO t5(a, b) VALUES('abc', 'def');
|
||||
UPDATE t5 SET a='abc', b='def';
|
||||
} {}
|
||||
|
||||
do_execsql_test 2.3.2 {
|
||||
SELECT name, coll, key FROM pragma_index_xinfo('t5');
|
||||
} {b BINARY 1 a BINARY 1}
|
||||
|
||||
|
||||
do_execsql_test 2.4.1 {
|
||||
CREATE TABLE t6 (
|
||||
a COLLATE nocase, b, c UNIQUE, PRIMARY KEY(b, a)
|
||||
@@ -153,6 +170,11 @@ do_execsql_test 2.4.2 {
|
||||
SELECT * FROM t6 ORDER BY c;
|
||||
} {ABC def ghi ABC def ghi}
|
||||
|
||||
do_execsql_test 2.4.3 {
|
||||
SELECT name, coll, key FROM pragma_index_xinfo('t6');
|
||||
} {b BINARY 1 a nocase 1 c BINARY 0}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Unless the destination table is completely empty, the xfer optimization
|
||||
# is disabled for WITHOUT ROWID tables. The following tests check for
|
||||
|
@@ -24,6 +24,9 @@ do_execsql_test without_rowid6-100 {
|
||||
INSERT INTO t1(a,b,c,d,e) SELECT i, i+1000, printf('x%dy',i), 0, 0 FROM c;
|
||||
ANALYZE;
|
||||
} {}
|
||||
do_execsql_test without_rowid6-101 {
|
||||
SELECT name, key FROM pragma_index_xinfo('t1');
|
||||
} {a 1 b 1 c 1 d 1 e 0}
|
||||
do_execsql_test without_rowid6-110 {
|
||||
SELECT c FROM t1 WHERE a=123;
|
||||
} {x123y}
|
||||
@@ -51,6 +54,9 @@ do_execsql_test without_rowid6-200 {
|
||||
INSERT INTO t1(a,b,c) VALUES(1,8,3),(4,5,6),(7,2,9);
|
||||
SELECT a FROM t1 WHERE b>3 ORDER BY b;
|
||||
} {4 1}
|
||||
do_execsql_test without_rowid6-201 {
|
||||
SELECT name, key FROM pragma_index_xinfo('t1');
|
||||
} {b 1 a 0 c 0}
|
||||
do_execsql_test without_rowid6-210 {
|
||||
EXPLAIN QUERY PLAN
|
||||
SELECT a FROM t1 WHERE b>3 ORDER BY b;
|
||||
@@ -105,6 +111,9 @@ do_execsql_test without_rowid6-500 {
|
||||
INSERT INTO t1(a,b,c) VALUES(1,8,3),(4,5,6),(7,2,9);
|
||||
SELECT a FROM t1 WHERE b>3 ORDER BY b;
|
||||
} {4 1}
|
||||
do_execsql_test without_rowid6-501 {
|
||||
SELECT name, key FROM pragma_index_xinfo('t1');
|
||||
} {b 1 c 1 a 0}
|
||||
do_execsql_test without_rowid6-510 {
|
||||
EXPLAIN QUERY PLAN
|
||||
SELECT a FROM t1 WHERE b>3 ORDER BY b;
|
||||
|
56
test/without_rowid7.test
Normal file
56
test/without_rowid7.test
Normal file
@@ -0,0 +1,56 @@
|
||||
# 2019 July 17
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix without_rowid7
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a, b COLLATE nocase, PRIMARY KEY(a, a, b)) WITHOUT ROWID;
|
||||
}
|
||||
|
||||
do_catchsql_test 1.1 {
|
||||
INSERT INTO t1 VALUES(1, 'one'), (1, 'ONE');
|
||||
} {1 {UNIQUE constraint failed: t1.a, t1.b}}
|
||||
|
||||
|
||||
do_execsql_test 2.0 {
|
||||
CREATE TABLE t2(a, b, PRIMARY KEY(a COLLATE nocase, a)) WITHOUT ROWID;
|
||||
}
|
||||
|
||||
do_execsql_test 2.1 {
|
||||
INSERT INTO t2 VALUES(1, 'one');
|
||||
SELECT b FROM t2;
|
||||
} {one}
|
||||
|
||||
do_execsql_test 2.2a {
|
||||
PRAGMA index_info(t2);
|
||||
} {0 0 a 1 0 a}
|
||||
do_execsql_test 2.2b {
|
||||
SELECT *, '|' FROM pragma_index_info('t2');
|
||||
} {0 0 a | 1 0 a |}
|
||||
do_execsql_test 2.3a {
|
||||
PRAGMA index_xinfo(t2);
|
||||
} {0 0 a 0 nocase 1 1 0 a 0 BINARY 1 2 1 b 0 BINARY 0}
|
||||
do_execsql_test 2.3b {
|
||||
SELECT *, '|' FROM pragma_index_xinfo('t2');
|
||||
} {0 0 a 0 nocase 1 | 1 0 a 0 BINARY 1 | 2 1 b 0 BINARY 0 |}
|
||||
|
||||
do_execsql_test 2.4 {
|
||||
CREATE TABLE t3(a, b, PRIMARY KEY(a COLLATE nocase, a));
|
||||
PRAGMA index_info(t3);
|
||||
} {}
|
||||
|
||||
|
||||
|
||||
finish_test
|
Reference in New Issue
Block a user