Some inserts and queries working for multi-column primary keys

and WITHOUT ROWID.

FossilOrigin-Name: b21d831b2aa55507dd9def2acb02cdbffddf10d1
This commit is contained in:
drh 2013-10-23 13:30:58 +00:00
parent ec95c44175
commit ad124329ab
10 changed files with 44 additions and 39 deletions

View File

@ -1,5 +1,5 @@
C Some\ssimple\sinserts\sand\squeries\sworking\son\sWITHOUT\sROWID\stables.
D 2013-10-23T01:57:32.661
C Some\sinserts\sand\squeries\sworking\sfor\smulti-column\sprimary\skeys\nand\sWITHOUT\sROWID.
D 2013-10-23T13:30:58.697
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 0522b53cdc1fcfc18f3a98e0246add129136c654
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -168,13 +168,13 @@ F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
F src/btree.c 509722ce305471b626d3401c0631a808fd33237b
F src/btree.h bfe0e8c5759b4ec77b0d18390064a6ef3cdffaaf
F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0
F src/build.c 2b8af1054c5db8dd78675c847adcbe4999af0403
F src/build.c 029e1709651df95c75477c334be7bc1ea9332e6d
F src/callback.c f99a8957ba2adf369645fac0db09ad8adcf1caa2
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c ea4b7f3623a0fcb1146e7f245d7410033e86859c
F src/date.c 593c744b2623971e45affd0bde347631bdfa4625
F src/delete.c c1547dbf732c9987d109b6f45729b4a70e14659e
F src/expr.c 040c0d340c6eed1d7316407fcd8ea6d4a50dc9d9
F src/expr.c 3180b6332072b263f845592e72e92971af562ab0
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c 628f81177299660a86e40359b3689b81f517e125
F src/func.c 2c47b65e6e00e3e9374942f28254faf8adafe398
@ -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 e8aeca40de34d936118157e3afc5a0551cda9c66
F src/insert.c f95fb9bf2ca2ed222e30087ebfbc41cdcaf45b4e
F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12
F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b
@ -218,12 +218,12 @@ F src/printf.c da9119eb31a187a4b99f60aa4a225141c0ebb74b
F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68
F src/resolve.c 572585a96bf282bb9c3d9e08785ec3cae21dc488
F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
F src/select.c 15127b54cc11defb2cddef6914e1f384501a61c4
F src/select.c dbcd2271470b5d074252ea75e2e50f3544638b49
F src/shell.c 6f11f0e9ded63d48e306f2c6858c521e568a47bb
F src/sqlite.h.in 547a44dd4ff4d975e92a645ea2d609e543a83d0f
F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e
F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc
F src/sqliteInt.h 7cde277316177b00d1daeb6e4a3eebbcb1aff4ea
F src/sqliteInt.h dc7c57e1d792cda4af5a21bc9566a9afe63f977f
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@ -279,11 +279,11 @@ F src/update.c 2bb5a267796e6d0177ef5689487c3688de5c309e
F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
F src/util.c 2fa6c821d28bbdbeec1b2a7b091a281c9ef8f918
F src/vacuum.c f313bc97123a4dd4bfd3f50a00c4d44c08a5b1b7
F src/vdbe.c 3d960c844cee53830f33717b4f5d23d7ee56685f
F src/vdbe.c 9970b726e045a4098b41009ab35d3528cef7c79e
F src/vdbe.h 4f554b5627f26710c4c36d919110a3fc611ca5c4
F src/vdbeInt.h ff57f67aee1ba26a3a47e786533dab155ab6dad6
F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed
F src/vdbeaux.c 55f4858fe6abd84bd7311acbf30a75a28903ec25
F src/vdbeaux.c 6d59c132174a7e9152f0ca2db8f0f3ec97ef199b
F src/vdbeblob.c ef973d8d9f8170015343dd8824f795da675caa87
F src/vdbemem.c 6087553f2c61c06c8e1ab3959a60e174d6240c98
F src/vdbesort.c 3937e06b2a0e354500e17dc206ef4c35770a5017
@ -298,7 +298,7 @@ F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
F test/all.test 6ff7b43c2b4b905c74dc4a813d201d0fa64c5783
F test/alter.test b955ec265bca952bd23aa80a2d9bf6e69688694b
F test/alter.test e88dfa77e020c2b48e52a8020c70171ab828e079
F test/alter2.test 7ea05c7d92ac99349a802ef7ada17294dd647060
F test/alter3.test 49c9d9fba2b8fcdce2dedeca97bbf1f369cc548d
F test/alter4.test 8e93bf7a7e6919b14b0c9a6c1e4908bcf21b0165
@ -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 35a3606071685aa5196951f4bdddb136589ea216
R 7bad51a408f97a3987f0c85c7f87eccd
P 3f8016dee24213ec83a02d71ad2698789cc3a818
R 8d5debd82aac9a40f36ea419916ec920
U drh
Z 6da9ec3dec29a9e1ff505c84577a827e
Z d4d1d21b1888e64aec811a14e29e0bcc

View File

@ -1 +1 @@
3f8016dee24213ec83a02d71ad2698789cc3a818
b21d831b2aa55507dd9def2acb02cdbffddf10d1

View File

@ -4027,14 +4027,15 @@ void sqlite3Reindex(Parse *pParse, Token *pName1, Token *pName2){
*/
KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){
int i;
int nCol = pIdx->nKeyCol;
int nCol = pIdx->nColumn;
int nKey = pIdx->nKeyCol;
KeyInfo *pKey;
pKey = sqlite3KeyInfoAlloc(pParse->db, nCol);
pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
if( pKey ){
for(i=0; i<nCol; i++){
char *zColl = pIdx->azColl[i];
assert( zColl );
if( zColl==0 ) zColl = "BINARY";
pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl);
pKey->aSortOrder[i] = pIdx->aSortOrder[i];
}

View File

@ -1728,7 +1728,7 @@ int sqlite3CodeSubselect(
pExpr->iTable = pParse->nTab++;
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1);
pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1);
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
/* Case 1: expr IN (SELECT ...)

View File

@ -69,15 +69,15 @@ const char *sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
int n;
Table *pTab = pIdx->pTable;
sqlite3 *db = sqlite3VdbeDb(v);
pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nKeyCol+2);
pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
if( !pIdx->zColAff ){
db->mallocFailed = 1;
return 0;
}
for(n=0; n<pIdx->nKeyCol; n++){
pIdx->zColAff[n] = pTab->aCol[pIdx->aiColumn[n]].affinity;
for(n=0; n<pIdx->nColumn; n++){
i16 x = pIdx->aiColumn[n];
pIdx->zColAff[n] = x<0 ? SQLITE_AFF_INTEGER : pTab->aCol[x].affinity;
}
pIdx->zColAff[n++] = SQLITE_AFF_INTEGER;
pIdx->zColAff[n] = 0;
}

View File

@ -803,18 +803,20 @@ static void selectInnerLoop(
}
/*
** Allocate a KeyInfo object sufficient for an index of N columns.
** Allocate a KeyInfo object sufficient for an index of N key columns and
** X extra columns.
**
** Actually, always allocate one extra column for the rowid at the end
** of the index. So the KeyInfo returned will have space sufficient for
** N+1 columns.
*/
KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N){
KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
KeyInfo *p = sqlite3DbMallocZero(db,
sizeof(KeyInfo) + (N+1)*(sizeof(CollSeq*)+1));
sizeof(KeyInfo) + (N+X)*(sizeof(CollSeq*)+1));
if( p ){
p->aSortOrder = (u8*)&p->aColl[N+1];
p->aSortOrder = (u8*)&p->aColl[N+X];
p->nField = (u16)N;
p->nXField = (u16)X;
p->enc = ENC(db);
p->db = db;
}
@ -844,7 +846,7 @@ static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){
int i;
nExpr = pList->nExpr;
pInfo = sqlite3KeyInfoAlloc(db, nExpr);
pInfo = sqlite3KeyInfoAlloc(db, nExpr, 1);
if( pInfo ){
for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){
CollSeq *pColl;
@ -1988,7 +1990,7 @@ static int multiSelect(
assert( p->pRightmost==p );
nCol = p->pEList->nExpr;
pKeyInfo = sqlite3KeyInfoAlloc(db, nCol);
pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
if( !pKeyInfo ){
rc = SQLITE_NOMEM;
goto multi_select_end;
@ -2367,7 +2369,7 @@ static int multiSelectOrderBy(
assert( pItem->iOrderByCol>0 && pItem->iOrderByCol<=p->pEList->nExpr );
aPermute[i] = pItem->iOrderByCol - 1;
}
pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy);
pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy, 1);
if( pKeyMerge ){
for(i=0; i<nOrderBy; i++){
CollSeq *pColl;
@ -2405,7 +2407,7 @@ static int multiSelectOrderBy(
regPrev = pParse->nMem+1;
pParse->nMem += nExpr+1;
sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
pKeyDup = sqlite3KeyInfoAlloc(db, nExpr);
pKeyDup = sqlite3KeyInfoAlloc(db, nExpr, 1);
if( pKeyDup ){
for(i=0; i<nExpr; i++){
pKeyDup->aColl[i] = multiSelectCollSeq(pParse, p, i);
@ -4654,7 +4656,8 @@ int sqlite3Select(
}
/* Open a read-only cursor, execute the OP_Count, close the cursor. */
sqlite3VdbeAddOp3(v, OP_OpenRead, iCsr, iRoot, iDb);
sqlite3VdbeAddOp4(v, OP_OpenRead, iCsr, iRoot, iDb,
SQLITE_INT_TO_PTR(1), P4_INT32);
if( pKeyInfo ){
sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO_HANDOFF);
}

View File

@ -1518,7 +1518,8 @@ struct FKey {
struct KeyInfo {
sqlite3 *db; /* The database connection */
u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
u16 nField; /* Maximum index for aColl[] and aSortOrder[] */
u16 nField; /* Number of key columns in the index */
u16 nXField; /* Number of columns beyond the key columns */
u8 *aSortOrder; /* Sort order for each column. */
CollSeq *aColl[1]; /* Collating sequence for each term of the key */
};
@ -3139,7 +3140,7 @@ void sqlite3MinimumFileFormat(Parse*, int, int);
void sqlite3SchemaClear(void *);
Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int);
KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
void (*)(sqlite3_context*,int,sqlite3_value **),

View File

@ -3218,7 +3218,7 @@ case OP_OpenWrite: {
if( pOp->p4type==P4_KEYINFO ){
pKeyInfo = pOp->p4.pKeyInfo;
pKeyInfo->enc = ENC(p->db);
nField = pKeyInfo->nField+1;
nField = pKeyInfo->nField+pKeyInfo->nXField;
}else if( pOp->p4type==P4_INT32 ){
nField = pOp->p4.i;
}

View File

@ -752,10 +752,12 @@ void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){
KeyInfo *pOrig, *pNew;
pOrig = (KeyInfo*)zP4;
pOp->p4.pKeyInfo = pNew = sqlite3KeyInfoAlloc(db, pOrig->nField);
pNew = sqlite3KeyInfoAlloc(db, pOrig->nField, pOrig->nXField);
pOp->p4.pKeyInfo = pNew;
if( pNew ){
memcpy(pNew->aColl, pOrig->aColl, pOrig->nField*sizeof(pNew->aColl[0]));
memcpy(pNew->aSortOrder, pOrig->aSortOrder, pOrig->nField);
int n = pOrig->nField+pOrig->nXField;
memcpy(pNew->aColl, pOrig->aColl, n*sizeof(pNew->aColl[0]));
memcpy(pNew->aSortOrder, pOrig->aSortOrder, n);
pOp->p4type = P4_KEYINFO;
}else{
p->db->mallocFailed = 1;

View File

@ -863,7 +863,6 @@ foreach {tn tbl} $system_table_list {
#------------------------------------------------------------------------
# Verify that ALTER TABLE works on tables with the WITHOUT rowid option.
#
if 0 {
do_execsql_test alter-16.1 {
CREATE TABLE t16a(a TEXT, b REAL, c INT, PRIMARY KEY(a,b)) WITHOUT rowid;
INSERT INTO t16a VALUES('abc',1.25,99);
@ -875,6 +874,5 @@ do_execsql_test alter-16.2 {
ALTER TABLE t16a RENAME TO t16a_rn;
SELECT * FROM t16a_rn ORDER BY a;
} {abc 1.25 99 xyzzy cba 5.5 98 fizzle}
}
finish_test