Change the sqlite3OpenTable() utility to open the PRIMARY KEY index when

reading a WITHOUT ROWID table.

FossilOrigin-Name: 247f389930aededaa54ecb792748aa8d0ad6d57b
This commit is contained in:
drh 2013-10-23 23:37:02 +00:00
parent 4415628a4a
commit dd9930ef20
5 changed files with 27 additions and 23 deletions

View File

@ -1,5 +1,5 @@
C Construct\ssecondary\sindices\son\sWITHOUT\sROWID\stables.
D 2013-10-23T22:23:03.281
C Change\sthe\ssqlite3OpenTable()\sutility\sto\sopen\sthe\sPRIMARY\sKEY\sindex\swhen\nreading\sa\sWITHOUT\sROWID\stable.
D 2013-10-23T23:37:02.093
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 0522b53cdc1fcfc18f3a98e0246add129136c654
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -168,7 +168,7 @@ F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
F src/btree.c 509722ce305471b626d3401c0631a808fd33237b
F src/btree.h bfe0e8c5759b4ec77b0d18390064a6ef3cdffaaf
F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0
F src/build.c 6970691b8d22c6eb2c1ab0078e4d25c939acfdad
F src/build.c 2dccf54c05a0102fce82a3147c39a4b582a7eb60
F src/callback.c f99a8957ba2adf369645fac0db09ad8adcf1caa2
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c ea4b7f3623a0fcb1146e7f245d7410033e86859c
@ -182,7 +182,7 @@ F src/global.c 5caf4deab621abb45b4c607aad1bd21c20aac759
F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4
F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
F src/insert.c 288b90185e7c01777e14b117f85414a658ee7cdb
F src/insert.c c028df48f0564b43831ce8a14d1e14ac07b6729c
F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12
F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b
@ -292,7 +292,7 @@ F src/vtab.c 5a423b042eb1402ef77697d03d6a67378d97bc8d
F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
F src/walker.c e9e593d5bb798c3e67fc3893dfe7055c9e7d8d74
F src/where.c 13add0a866a75adb345abfa2ad25585322d472f3
F src/where.c 3dcdb0912101571b8821d564b90964bb34ea7ad1
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
@ -1127,7 +1127,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
P 36bcc9cb885523fba2f3b0d152de9e08073668c1
R 5319af9bbb603de112b9787a2a60f8ed
P 2c028ddc85cb45746cad6ab0cefd99134fbd50d7
R 09a1279eaef47a31655fe176c982c7ce
U drh
Z 289de8cc66e2b52514de0b537df4236c
Z faf48e5960db188516b7851e14254c4b

View File

@ -1 +1 @@
2c028ddc85cb45746cad6ab0cefd99134fbd50d7
247f389930aededaa54ecb792748aa8d0ad6d57b

View File

@ -2631,16 +2631,7 @@ static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
/* Open the table. Loop through all rows of the table, inserting index
** records into the sorter. */
if( HasRowid(pTab) ){
sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
}else{
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
assert( pPk!=0 );
assert( pPk->tnum=pTab->tnum );
sqlite3VdbeAddOp4(v, OP_OpenRead, iTab, pPk->tnum, iDb,
(char*)sqlite3IndexKeyinfo(pParse, pPk),
P4_KEYINFO_HANDOFF);
}
sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
regRecord = sqlite3GetTempReg(pParse);

View File

@ -15,7 +15,13 @@
#include "sqliteInt.h"
/*
** Generate code that will open a table for reading.
** Generate code that will open table pTab for reading or writing
** on cursor iCur.
**
** Always acquire a table lock. Always do the open for rowid tables.
** For WITHOUT ROWID tables, only do read opens, and then open the
** PRIMARY KEY index, not the main table, since the main table doesn't
** exist.
*/
void sqlite3OpenTable(
Parse *p, /* Generate code into this VDBE */
@ -30,8 +36,15 @@ void sqlite3OpenTable(
assert( opcode==OP_OpenWrite || opcode==OP_OpenRead );
sqlite3TableLock(p, iDb, pTab->tnum, (opcode==OP_OpenWrite)?1:0, pTab->zName);
if( HasRowid(pTab) ){
sqlite3VdbeAddOp3(v, opcode, iCur, pTab->tnum, iDb);
sqlite3VdbeChangeP4(v, -1, SQLITE_INT_TO_PTR(pTab->nCol), P4_INT32);
sqlite3VdbeAddOp4(v, opcode, iCur, pTab->tnum, iDb,
SQLITE_INT_TO_PTR(pTab->nCol), P4_INT32);
VdbeComment((v, "%s", pTab->zName));
}else if( opcode==OP_OpenRead ){
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
assert( pPk!=0 );
assert( pPk->tnum=pTab->tnum );
sqlite3VdbeAddOp4(v, opcode, iCur, pPk->tnum, iDb,
(char*)sqlite3IndexKeyinfo(p, pPk), P4_KEYINFO_HANDOFF);
VdbeComment((v, "%s", pTab->zName));
}
}

View File

@ -5955,7 +5955,7 @@ WhereInfo *sqlite3WhereBegin(
sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
testcase( !pWInfo->okOnePass && pTab->nCol==BMS-1 );
testcase( !pWInfo->okOnePass && pTab->nCol==BMS );
if( !pWInfo->okOnePass && pTab->nCol<BMS ){
if( !pWInfo->okOnePass && pTab->nCol<BMS && HasRowid(pTab) ){
Bitmask b = pTabItem->colUsed;
int n = 0;
for(; b; b=b>>1, n++){}