Compare commits

...

3 Commits

Author SHA1 Message Date
drh c4811b124e Improvements to the DELETE code generator for the one-pass case. Avoid
some OP_Goto instructions.  Read content from the index cursor if the
index cursor is valid and was used to locate the row that is to be deleted.

FossilOrigin-Name: 58cc257aeb3ce75b8d3811b568cb8a677f6730a2
2015-01-29 15:53:19 +00:00
drh ba5e802c37 Avoid overlength command lines in Makefile.msc when using TOP= with a large
directory name.

FossilOrigin-Name: 0cdd59bf36aa4c2cad9a15bb7237643fb4222d55
2015-01-29 14:48:36 +00:00
drh a5febc859f Experimental sqlite_db_config() setting to disable writing to all btrees
except for one btree with a particular root page.

FossilOrigin-Name: 2305411097c4985b61c5faf4361c4da8414101f2
2015-01-29 02:26:40 +00:00
10 changed files with 118 additions and 38 deletions
+18 -12
View File
@@ -714,7 +714,7 @@ LIBRESOBJS =
# All of the source code files.
#
SRC = \
SRC1 = \
$(TOP)\src\alter.c \
$(TOP)\src\analyze.c \
$(TOP)\src\attach.c \
@@ -764,7 +764,8 @@ SRC = \
$(TOP)\src\os_setup.h \
$(TOP)\src\os_unix.c \
$(TOP)\src\os_win.c \
$(TOP)\src\os_win.h \
$(TOP)\src\os_win.h
SRC2 = \
$(TOP)\src\pager.c \
$(TOP)\src\pager.h \
$(TOP)\src\parse.y \
@@ -811,15 +812,14 @@ SRC = \
# Source code for extensions
#
SRC = $(SRC) \
SRC3 = \
$(TOP)\ext\fts1\fts1.c \
$(TOP)\ext\fts1\fts1.h \
$(TOP)\ext\fts1\fts1_hash.c \
$(TOP)\ext\fts1\fts1_hash.h \
$(TOP)\ext\fts1\fts1_porter.c \
$(TOP)\ext\fts1\fts1_tokenizer.h \
$(TOP)\ext\fts1\fts1_tokenizer1.c
SRC = $(SRC) \
$(TOP)\ext\fts1\fts1_tokenizer1.c \
$(TOP)\ext\fts2\fts2.c \
$(TOP)\ext\fts2\fts2.h \
$(TOP)\ext\fts2\fts2_hash.c \
@@ -829,7 +829,7 @@ SRC = $(SRC) \
$(TOP)\ext\fts2\fts2_tokenizer.h \
$(TOP)\ext\fts2\fts2_tokenizer.c \
$(TOP)\ext\fts2\fts2_tokenizer1.c
SRC = $(SRC) \
SRC4 = \
$(TOP)\ext\fts3\fts3.c \
$(TOP)\ext\fts3\fts3.h \
$(TOP)\ext\fts3\fts3Int.h \
@@ -846,18 +846,16 @@ SRC = $(SRC) \
$(TOP)\ext\fts3\fts3_tokenize_vtab.c \
$(TOP)\ext\fts3\fts3_unicode.c \
$(TOP)\ext\fts3\fts3_unicode2.c \
$(TOP)\ext\fts3\fts3_write.c
SRC = $(SRC) \
$(TOP)\ext\fts3\fts3_write.c \
$(TOP)\ext\icu\sqliteicu.h \
$(TOP)\ext\icu\icu.c
SRC = $(SRC) \
$(TOP)\ext\icu\icu.c \
$(TOP)\ext\rtree\rtree.h \
$(TOP)\ext\rtree\rtree.c
# Generated source code files
#
SRC = $(SRC) \
SRC5 = \
keywordhash.h \
opcodes.c \
opcodes.h \
@@ -865,6 +863,10 @@ SRC = $(SRC) \
parse.h \
sqlite3.h
# All source code files.
#
SRC = $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5)
# Source code to the test files.
#
TESTSRC = \
@@ -1052,7 +1054,11 @@ mptester.exe: $(TOP)\mptest\mptest.c libsqlite3.lib $(LIBRESOBJS) sqlite3.h
.target_source: $(SRC) $(TOP)\tool\vdbe-compress.tcl
-rmdir /S/Q tsrc
-mkdir tsrc
for %i in ($(SRC)) do copy /Y %i tsrc
for %i in ($(SRC1)) do copy /Y %i tsrc
for %i in ($(SRC2)) do copy /Y %i tsrc
for %i in ($(SRC3)) do copy /Y %i tsrc
for %i in ($(SRC4)) do copy /Y %i tsrc
for %i in ($(SRC5)) do copy /Y %i tsrc
del /Q tsrc\sqlite.h.in tsrc\parse.y
$(TCLSH_CMD) $(TOP)\tool\vdbe-compress.tcl $(OPTS) < tsrc\vdbe.c > vdbe.new
move vdbe.new tsrc\vdbe.c
+14 -14
View File
@@ -1,9 +1,9 @@
C Fix\sharmless\scompiler\swarnings.
D 2015-01-27T21:24:33.191
C Improvements\sto\sthe\sDELETE\scode\sgenerator\sfor\sthe\sone-pass\scase.\s\sAvoid\nsome\sOP_Goto\sinstructions.\s\sRead\scontent\sfrom\sthe\sindex\scursor\sif\sthe\nindex\scursor\sis\svalid\sand\swas\sused\sto\slocate\sthe\srow\sthat\sis\sto\sbe\sdeleted.
D 2015-01-29T15:53:19.350
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F Makefile.msc 2b1cb8881bdefcb0a8ed41c34c81cfa630374222
F Makefile.msc 1edfd7dd45d98a04f9a2fa81a01c49faeb628578
F Makefile.vxworks e1b65dea203f054e71653415bd8f96dcaed47858
F README.md d58e3bebc0a4145e0f2a87994015fdb575a8e866
F VERSION d846487aff892625eb8e75960234e7285f0462fe
@@ -181,7 +181,7 @@ F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0
F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463
F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887
F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac
F src/delete.c bd1a91ddd247ce13004075251e0b7fe2bf9925ef
F src/delete.c 66c10f83d3b0f37282f5b91f8a9192f4ce4a82c2
F src/expr.c abe930897ccafae3819fd2855cbc1b00c262fd12
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12
@@ -190,12 +190,12 @@ F src/global.c 12561d70a1b25f67b21154622bb1723426724f75
F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5
F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
F src/insert.c 5b9243a33726008cc4132897d2be371db12a13be
F src/insert.c 57b087ad5c7580bd62b807dcdbd70c54b2bb4228
F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e
F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770
F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660
F src/main.c 05bf368c934cc73d02906030846eb4d1818c10f7
F src/main.c 6a6688cf02372c744f8a67e7b396d53f378e49a2
F src/malloc.c 740db54387204c9a2eb67c6d98e68b08e9ef4eab
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987
@@ -230,11 +230,11 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada
F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
F src/select.c 1f2087523007c42900ffcbdeaef06a23ad9329fc
F src/shell.c efd35900484377d2159189968c3445afefee3e41
F src/sqlite.h.in 9dfc99d6533d36d6a549c4f3f01cacc8be956ada
F src/shell.c ff4dafe42c9d282b06cbcaf0c285c553d7d5daa1
F src/sqlite.h.in 7e7ce8ea342d59f109dcf3185374ebe1a6c0e4dd
F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d
F src/sqliteInt.h eaf210295b551d4e40e622aec1b2261c0b28f844
F src/sqliteInt.h d70bca4e33ee931a545172679a3013e15528c3bd
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c 81712116e826b0089bb221b018929536b2b5406f
F src/table.c e7a09215315a978057fb42c640f890160dbcc45e
@@ -292,7 +292,7 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13
F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c
F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e
F src/vacuum.c 9b30ec729337dd012ed88d4c292922c8ef9cf00c
F src/vdbe.c ddfc977981cd6324668aa6b114045eb1c677421a
F src/vdbe.c 55f4db96c3d2bee17c66f244e4fc51fb0f09fed2
F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3
F src/vdbeInt.h 9bb69ff2447c34b6ccc58b34ec35b615f86ead78
F src/vdbeapi.c 4bc511a46b9839392ae0e90844a71dc96d9dbd71
@@ -1237,7 +1237,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P adc9283dd9bc3a6463f8c4fe23dd58a3712c349d
R 57729c2b510493b06603a65c6ea41133
U mistachkin
Z 7155fc25674fe331bcb8023f01301b6b
P 0cdd59bf36aa4c2cad9a15bb7237643fb4222d55
R 139902d9a4e02d98a72f3dedb9a073bc
U drh
Z ea315405c3cfce5f5aed8dbe7ead251e
+1 -1
View File
@@ -1 +1 @@
e7d2ec048c88237c124fbe598f8f7e950d43d90f
58cc257aeb3ce75b8d3811b568cb8a677f6730a2
+10 -10
View File
@@ -247,7 +247,6 @@ void sqlite3DeleteFrom(
int iRowSet = 0; /* Register for rowset of rows to delete */
int addrBypass = 0; /* Address of jump over the delete logic */
int addrLoop = 0; /* Top of the delete loop */
int addrDelete = 0; /* Jump directly to the delete logic */
int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
#ifndef SQLITE_OMIT_TRIGGER
@@ -437,7 +436,6 @@ void sqlite3DeleteFrom(
if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen);
addrDelete = sqlite3VdbeAddOp0(v, OP_Goto); /* Jump to DELETE logic */
}else if( pPk ){
/* Construct a composite key for the row to be deleted and remember it */
iKey = ++pParse->nMem;
@@ -451,13 +449,11 @@ void sqlite3DeleteFrom(
sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
}
/* End of the WHERE loop */
sqlite3WhereEnd(pWInfo);
/* End of the WHERE loop. */
if( okOnePass ){
/* Bypass the delete logic below if the WHERE loop found zero rows */
addrBypass = sqlite3VdbeMakeLabel(v);
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBypass);
sqlite3VdbeJumpHere(v, addrDelete);
}else{
sqlite3WhereEnd(pWInfo);
}
/* Unless this is a view, open cursors for the table we are
@@ -513,6 +509,7 @@ void sqlite3DeleteFrom(
/* End of the loop over all rowids/primary-keys. */
if( okOnePass ){
sqlite3WhereEnd(pWInfo);
sqlite3VdbeResolveLabel(v, addrBypass);
}else if( pPk ){
sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
@@ -674,9 +671,11 @@ void sqlite3GenerateRowDelete(
** fire the INSTEAD OF triggers). */
if( pTab->pSelect==0 ){
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0);
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
if( count ){
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
if( !WRITE_RESTRICT(pParse->db, pTab->tnum) ){
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
if( count ){
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
}
}
}
@@ -736,6 +735,7 @@ void sqlite3GenerateRowIndexDelete(
assert( iIdxCur+i!=iDataCur || pPk==pIdx );
if( aRegIdx!=0 && aRegIdx[i]==0 ) continue;
if( pIdx==pPk ) continue;
if( WRITE_RESTRICT(pParse->db, pIdx->tnum) ) continue;
VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName));
r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1,
&iPartIdxLabel, pPrior, r1);
+5
View File
@@ -1366,6 +1366,7 @@ void sqlite3GenerateConstraintChecks(
int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
if( WRITE_RESTRICT(db, pIdx->tnum) ) continue;
if( bAffinityDone==0 ){
sqlite3TableAffinity(v, pTab, regNewData+1);
bAffinityDone = 1;
@@ -1545,6 +1546,7 @@ void sqlite3CompleteInsertion(
){
Vdbe *v; /* Prepared statements under construction */
Index *pIdx; /* An index being inserted or updated */
sqlite3 *db;
u8 pik_flags; /* flag values passed to the btree insert */
int regData; /* Content registers (after the rowid) */
int regRec; /* Register holding assembled record for the table */
@@ -1554,8 +1556,10 @@ void sqlite3CompleteInsertion(
v = sqlite3GetVdbe(pParse);
assert( v!=0 );
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
db = pParse->db;
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
if( aRegIdx[i]==0 ) continue;
if( WRITE_RESTRICT(db, pIdx->tnum) ) continue;
bAffinityDone = 1;
if( pIdx->pPartIdxWhere ){
sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
@@ -1571,6 +1575,7 @@ void sqlite3CompleteInsertion(
if( pik_flags ) sqlite3VdbeChangeP5(v, pik_flags);
}
if( !HasRowid(pTab) ) return;
if( WRITE_RESTRICT(db, pTab->tnum) ) return;
regData = regNewData + 1;
regRec = sqlite3GetTempReg(pParse);
sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
+5
View File
@@ -725,6 +725,11 @@ int sqlite3_db_config(sqlite3 *db, int op, ...){
rc = setupLookaside(db, pBuf, sz, cnt);
break;
}
case SQLITE_DBCONFIG_WRITABLE_BTREE: {
db->onlyWritableBtree = va_arg(ap,int);
rc = SQLITE_OK;
break;
}
default: {
static const struct {
int op; /* The opcode */
+46
View File
@@ -2568,6 +2568,52 @@ static int do_meta_command(char *zLine, ShellState *p){
}
}else
if( c=='d' && n>1 && strncmp(azArg[0], "dbconfig", n)==0 ){
int nHit = 0, x;
open_db(p, 0);
if( nArg>=2 ){
n = (int)strlen(azArg[1]);
if( strncmp(azArg[1], "writable_btree",n)==0 ){
if( nArg!=3 ){
fprintf(stderr, "Usage: .dbconfig writable_btree N\n");
rc = 1;
}else{
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_BTREE,
integerValue(azArg[2]));
}
nHit = 1;
}else
if( strncmp(azArg[1], "enable_fkey",n)==0 ){
if( nArg!=3 ){
fprintf(stderr, "Usage: .dbconfig enable_fkey (1|0|-1)\n");
rc = 1;
}else{
sqlite3_db_config(p->db, SQLITE_DBCONFIG_ENABLE_FKEY,
integerValue(azArg[2]), &x);
printf("result: %d\n", x);
}
nHit = 1;
}else
if( strncmp(azArg[1], "enable_trigger",n)==0 ){
if( nArg!=3 ){
fprintf(stderr, "Usage: .dbconfig enable_trigger (1|0|-1)\n");
rc = 1;
}else{
sqlite3_db_config(p->db, SQLITE_DBCONFIG_ENABLE_TRIGGER,
integerValue(azArg[2]), &x);
printf("result: %d\n", x);
}
nHit = 1;
}
}
if( nHit==0 ){
fprintf(stderr, "Usage: .dbconfig COMMAND ARGS...\n");
fprintf(stderr,
"COMMAND is one of: writable_btree enable_fkey enable_trigger\n");
rc = 1;
}
}else
if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
open_db(p, 0);
/* When playing back a "dump", the content might appear in an order
+9
View File
@@ -1840,11 +1840,20 @@ struct sqlite3_mem_methods {
** following this call. The second parameter may be a NULL pointer, in
** which case the trigger setting is not reported back. </dd>
**
** <dt>SQLITE_DBCONFIG_WRITABLE_BTREE</dt>
** <dd> ^This option is used to disable INSERT and DELETE operations
** against all attached b-trees, except for b-trees that have a
** particular root page.
** There must be one additional integer argument which is the root page
** that is allowed to be written. If the argument is zero, then
** writing is allowed to all b-trees, as is normally the case.
**
** </dl>
*/
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
#define SQLITE_DBCONFIG_WRITABLE_BTREE 1004 /* int */
/*
+8
View File
@@ -1077,6 +1077,7 @@ struct sqlite3 {
u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
int nextPagesize; /* Pagesize after VACUUM if >0 */
int onlyWritableBtree; /* Do not write to any other b-tree */
u32 magic; /* Magic number for detect library misuse */
int nChange; /* Value returned by sqlite3_changes() */
int nTotalChange; /* Value returned by sqlite3_total_changes() */
@@ -1166,6 +1167,13 @@ struct sqlite3 {
#endif
};
/*
** This macro returns true if the only_writable_btree pragma is turned
** on and is set to a btree root node other than N.
*/
#define WRITE_RESTRICT(db,N) ((db)->onlyWritableBtree>0 && \
(db)->onlyWritableBtree!=(N))
/*
** A macro to discover the encoding of a database.
*/
+2 -1
View File
@@ -4191,7 +4191,8 @@ case OP_Delete: {
pC = p->apCsr[pOp->p1];
assert( pC!=0 );
assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
assert( pC->deferredMoveto==0 );
rc = sqlite3VdbeCursorMoveto(pC);
if( rc ) goto abort_due_to_error;
#ifdef SQLITE_DEBUG
/* The seek operation that positioned the cursor prior to OP_Delete will