aboutsummaryrefslogtreecommitdiff
path: root/src/insert.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2013-11-26 18:00:29 +0000
committerdrh <drh@noemail.net>2013-11-26 18:00:29 +0000
commit1b2ee4fe1afb4edd3d04e62daeb133df41809e38 (patch)
tree3f90016343959f3349a8086cb43c38cb4de975a3 /src/insert.c
parent212c6be1417860712de4b93b31342b72c9fa89dd (diff)
parent55fcab39be8186caac6c7d1262a7c943564623bb (diff)
downloadsqlite-1b2ee4fe1afb4edd3d04e62daeb133df41809e38.tar.gz
sqlite-1b2ee4fe1afb4edd3d04e62daeb133df41809e38.zip
Merge in performance enhancements from trunk.
FossilOrigin-Name: fc9ae839569eb28eb734c52d95676c59b2e27494
Diffstat (limited to 'src/insert.c')
-rw-r--r--src/insert.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/insert.c b/src/insert.c
index 1c89a38af..df1b3fc9c 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -820,7 +820,7 @@ void sqlite3Insert(
/* If this is not a view, open the table and and all indices */
if( !isView ){
int nIdx;
- nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, -1,
+ nIdx = sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, -1, 0,
&iDataCur, &iIdxCur);
aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
if( aRegIdx==0 ){
@@ -1692,16 +1692,19 @@ int sqlite3OpenTableAndIndices(
Table *pTab, /* Table to be opened */
int op, /* OP_OpenRead or OP_OpenWrite */
int iBase, /* Use this for the table cursor, if there is one */
+ u8 *aToOpen, /* If not NULL: boolean for each table and index */
int *piDataCur, /* Write the database source cursor number here */
int *piIdxCur /* Write the first index cursor number here */
){
int i;
int iDb;
+ int iDataCur;
Index *pIdx;
Vdbe *v;
assert( op==OP_OpenRead || op==OP_OpenWrite );
if( IsVirtual(pTab) ){
+ assert( aToOpen==0 );
*piDataCur = 0;
*piIdxCur = 1;
return 0;
@@ -1710,20 +1713,25 @@ int sqlite3OpenTableAndIndices(
v = sqlite3GetVdbe(pParse);
assert( v!=0 );
if( iBase<0 ) iBase = pParse->nTab;
- if( HasRowid(pTab) ){
- *piDataCur = iBase++;
- sqlite3OpenTable(pParse, *piDataCur, iDb, pTab, op);
+ iDataCur = iBase++;
+ if( piDataCur ) *piDataCur = iDataCur;
+ if( HasRowid(pTab) && (aToOpen==0 || aToOpen[0]) ){
+ sqlite3OpenTable(pParse, iDataCur, iDb, pTab, op);
}else{
sqlite3TableLock(pParse, iDb, pTab->tnum, op==OP_OpenWrite, pTab->zName);
}
- *piIdxCur = iBase;
+ if( piIdxCur ) *piIdxCur = iBase;
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
int iIdxCur = iBase++;
assert( pIdx->pSchema==pTab->pSchema );
- if( pIdx->autoIndex==2 && !HasRowid(pTab) ) *piDataCur = iIdxCur;
- sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
- sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
- VdbeComment((v, "%s", pIdx->zName));
+ if( pIdx->autoIndex==2 && !HasRowid(pTab) && piDataCur ){
+ *piDataCur = iIdxCur;
+ }
+ if( aToOpen==0 || aToOpen[i+1] ){
+ sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
+ sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
+ VdbeComment((v, "%s", pIdx->zName));
+ }
}
if( iBase>pParse->nTab ) pParse->nTab = iBase;
return i;