Commit Graph

102 Commits

Author SHA1 Message Date
dan
c456a76fb3 When generating individual loops for each ORed term of an OR scan, move any
constant WHERE expressions outside of the loop, as is done for top-level
loops.

FossilOrigin-Name: e4a022be4b069b08cfdfda5295461676b99d28e17bbbedfbcb362dec69de59bd
2017-06-22 16:51:16 +00:00
dan
940b5eaa5e Avoid updating unaffected indexes on a table as part of an UPDATE that requires
foreign key processing in some cases.

FossilOrigin-Name: 477bea9ed0dd0fa69896bfd16d9b1d22170cbab784e3279ce65c29c47e032f34
2017-04-11 19:58:55 +00:00
drh
79df77821a Refactor the Table.nRef field as Table.nTabRef for easier grepping.
FossilOrigin-Name: 9cae4c2e300e20304ced0dc8c1415c4922185928
2016-12-14 14:07:35 +00:00
dan
68a494c06f Fix a problem causing SQLite to return false "foreign key violation" errors
when there is a partial (i.e. WHERE constrained) UNIQUE index on the parent
key columns. This bug did not cause SQLite to allow illegal data to be
inserted into the database, only to reject legal operations.

FossilOrigin-Name: 850877d1ea43104cc215353414b870c340acced2
2016-12-13 16:57:49 +00:00
drh
abfd35ea03 Performance improvement and size reduction in the Expr node allocator
function sqlite3PExpr().

FossilOrigin-Name: 2a81763e68cdf9b8c46389b1e1a87bc2084b53e7
2016-12-06 22:47:23 +00:00
drh
e1c03b6233 Use sqlite3ExprAlloc() instead of sqlite3PExpr() for leaf nodes in the
expression tree, where appropriate.  This is both smaller and faster.

FossilOrigin-Name: afac0709cec577a7851e3711730712cf12eeb6af
2016-09-23 20:59:31 +00:00
drh
69c338263a Rename the Db.zName field to Db.zDbSName to make it more descriptive and to
distinguish it from all of the other "zName" variables scattered throughout
the code.

FossilOrigin-Name: 92a22f01343a898455fd61c3b8e7d7c954f5b569
2016-08-18 14:33:11 +00:00
drh
0b2c140a4d Fix a memory leak when a WITHOUT ROWID eponymous virtual table is used.
FossilOrigin-Name: 31b83a7d7e553163eb186fc966a885f237554ec2
2016-06-03 18:21:04 +00:00
drh
3875a96ad9 Remove a redundant test for disabling RESTRICT with defer_foreign_keys=ON.
FossilOrigin-Name: 9cdf813c6aaaddc01d2d4e04636c83fcda04d971
2016-03-30 14:17:36 +00:00
drh
2606aca80f Merge recent enhancements from trunk. Default page size is 4096. Writes
to statement journals are avoided.

FossilOrigin-Name: 456df3365e2df60e34762f2024bb551538b3f72b
2016-03-04 16:42:43 +00:00
mistachkin
9d970c3c93 Small optimization in FK handling.
FossilOrigin-Name: e0d25913b73a813f5987aa70b364b00f19351663
2016-02-25 21:38:28 +00:00
dan
aa9ffaba4a Disable the RESTRICT foreign key action if "PRAGMA defer_foreign_keys" is set.
FossilOrigin-Name: 9ffff484bb4b67c29dda6180d7d766ad13988fe1
2016-02-25 20:17:55 +00:00
dan
fd37e67b16 Disable the RESTRICT foreign key action if "PRAGMA defer_foreign_keys" is set.
FossilOrigin-Name: 8fea1166016c659ece83e0045bc348f478a9ba6a
2016-02-25 19:52:11 +00:00
drh
575fad6500 Add the slightly faster sqlite3DbMallocRawNN(db,n) routine for the majority
cases where db is guaranteed to be not NULL.

FossilOrigin-Name: 0a802e96ab06e2643834b83671fa8353da1a348d
2016-02-05 13:38:36 +00:00
drh
4a642b6060 Improvements to the way that OOM errors are processed.
FossilOrigin-Name: c3ef03478a5788c855b3aef385d43ae7f494f440
2016-02-05 01:55:27 +00:00
drh
40aced5c65 Add the sqlite3TokenInit() utility function.
FossilOrigin-Name: 7323175337b7ba85ac932ca892b28860f6a5b688
2016-01-22 17:48:09 +00:00
dan
2beb2c390b Disable the RESTRICT foreign key action if "PRAGMA defer_foreign_keys" is set.
FossilOrigin-Name: 82470d1c3a41221c78bcdd402b2219c4c21c43af
2016-01-21 17:25:56 +00:00
drh
f19aa5fa6f Changes to the way that the default BINARY collating sequence is recorded
result in a slightly smaller and slightly faster executable.  More work could
be done to make this cleaner.

FossilOrigin-Name: 2081d75767dc590b4c8457e5f8e5f18ba5f8eaa7
2015-12-30 16:51:20 +00:00
drh
4b92f98ccc Use symbolic names XN_ROWID and XN_EXPR in place of the (-1) and (-2)
magic numbers in Index.aiColumn[].  Add asserts to help verify that
Index.aiColumn[] is always used correctly.  Fix one place in FK processing
where Index.aiColumn[] was not being used correctly.

FossilOrigin-Name: 7d272aa62cd4cbbf4b5d04e3b918de27671e8301
2015-09-29 17:20:14 +00:00
drh
076e85f59c Add the sqlite3VdbeLoadString() and sqlite3VdbeMultiLoad() routines to help
with code generation, especially on PRAGMAs.  Rename sqlite3VdbeAddGoto()
to just sqlite3VdbeGoto().

FossilOrigin-Name: 847387ec8e6fef283899578fb232b2c23b00ee5b
2015-09-03 13:46:12 +00:00
drh
2991ba050b Add the sqlite3VdbeAddGoto(v,i) routine as a shorthand for
sqlite3VdbeAddOp2(v,OP_Goto,0,i).

FossilOrigin-Name: be78f413df1b0d874b44a866ef6bf17543d7e8a2
2015-09-02 18:19:00 +00:00
drh
e910769817 Use the sqlite3IndexColumnAffinity() routine to quickly and correctly find the
affinity of an index column.

FossilOrigin-Name: 1ee089a72d789002a0a377347fc51e08ab32fb14
2015-08-25 19:20:04 +00:00
dan
464083544e Ensure that tables names are dequoted exactly once by the trigger logic.
FossilOrigin-Name: 9d887b92f8086961e045f8acb9ee7a443796d411
2015-04-21 16:38:49 +00:00
drh
b6b676ea7c Fix some identifier name de-quoting issues in the foreign key and trigger logic.
FossilOrigin-Name: 59e92bd9521f1e8315a9a7e7fd3d63b0c75eaf0e
2015-04-21 03:13:47 +00:00
drh
e918aaba98 Fix foreign key CASCADE for cases where the parent key is an INTEGER PRIMARY
KEY and the parent table contains other columns named "rowid", "_rowid_",
and "oid".

FossilOrigin-Name: ed3cbaab6ad49b0cb5b17e44def26c866919387a
2015-04-10 12:04:57 +00:00
dan
d457271130 Fix some comments in fkey.c. Add tests to fkey8.test.
FossilOrigin-Name: 210cb2a6aaf780365064a26c0c99926bd6346e19
2014-12-17 14:38:45 +00:00
dan
0466883300 Experimental opimizations to speed up FK constraint CASCADE and SET NULL action processing.
FossilOrigin-Name: 35a20a5f22245c70faa51965951e8cc011defa93
2014-12-16 20:13:30 +00:00
peter.d.reid
60ec914c74 Fix typos in comments. No code changes.
FossilOrigin-Name: e62aab5e9290503869e1f4d5e0fefd2b4dee0a69
2014-09-06 16:39:46 +00:00
drh
acbcb7e013 Simplify the interface to the symbol table, saving 600 bytes of code space.
FossilOrigin-Name: 14b0f561fe15622b61c6676c9c455dca6b9ba5f0
2014-08-21 20:26:37 +00:00
drh
5f1d1d9c87 Refactoring: Change "pIndex->onError!=OE_None" to use a macro:
"IsUniqueIndex(pIndex)".  Easier to understand that way.

FossilOrigin-Name: e75b26ee357bb3d3c1a539b05d633ebf314726d7
2014-07-31 22:59:04 +00:00
drh
48dd1d8e28 Change the name of the Index.autoIndex field to Index.idxType and provide
symbolic names for the various values of that field rather than using
magic numbers.

FossilOrigin-Name: d16e575dacc811de0f7b58a0d1cd243678dce6c5
2014-05-27 18:18:58 +00:00
drh
3d77dee935 Add the SQLITE_NOTNULL P5 code for comparison operations - really a composite
of SQLITE_NULLEQ and SQLITE_JUMPIFNULL.  This flag indicates that NULL operands
are not possible and raises and assert() if NULL operands are seen.
Also omit an unnecessary scan of the sqlite_sequence table when writing
into an AUTOINCREMENT table.

FossilOrigin-Name: d2c047f304848e49864ed8c216b48fd671fa3916
2014-02-19 14:20:49 +00:00
drh
688852ab15 Add logic to do test coverage measurements on the VDBE code.
FossilOrigin-Name: ce184c7bb16988641d37c908d9b3042456d4be3d
2014-02-17 22:40:43 +00:00
drh
57bf4a8eeb Avoid unnecessary calls to applyAffinity() during INSERT and UPDATE
operations, especially for table that have indices and tables for which
all columns have affinity "NONE".

FossilOrigin-Name: 35b4d6e938164fabaf30b504c54cfd9a69060cee
2014-02-17 14:59:22 +00:00
drh
2bea7cde6e Fix harmless compiler warnings from clang scan-build.
FossilOrigin-Name: 8d002740bffca2a76d2dfbc1a67293d34f9de9ba
2013-11-18 11:20:50 +00:00
drh
511717c645 Fix harmless compiler warnings.
FossilOrigin-Name: 0077c0772a884b54d81fa3733aac6f0c364ef1a8
2013-11-08 17:13:23 +00:00
drh
2ec2fb2269 Reference count the KeyInfo object. Cache a copy of an appropriate KeyInfo
for each index in the Index object, and reuse that one copy as much as possible.

FossilOrigin-Name: defd5205a7cc3543cdd18f906f568e943b8b3a2c
2013-11-06 19:59:23 +00:00
drh
f9c8ce3ced Standardize the error messages generated by constraint failures to a format
of "$TYPE constraint failed: $DETAIL".  This involves many changes to the
expected output of test cases.

FossilOrigin-Name: 54b221929744b1bcdbcc2030fef2e510618afd41
2013-11-05 13:33:55 +00:00
drh
90e758ff1f Correctly handle self-referential foreign keys on WITHOUT ROWID tables.
FossilOrigin-Name: af128862ab6008df9dda1ee90f93f9efd629e259
2013-11-04 13:56:00 +00:00
drh
bd50a926ef Improved comments on foreign key logic.
FossilOrigin-Name: 1315d9109c7105f4a62bb2d43ca6948d41245129
2013-11-03 02:27:58 +00:00
drh
63f0eedf10 Many new test cases added, that mostly work. Currently 18 errors in
without_rowid3.test.  Also there is a hack marked by a /*FIXME*/ comment 
on at fkey.c:547 that needs fixing.

FossilOrigin-Name: 39e32187b66405e00dbd44685f6cdd269c90f5e5
2013-11-02 22:09:48 +00:00
drh
bbbdc83b52 The Index object now has nKeyCol and nColumn. nColumn is the total number
of columns and nKeyCol is the number of key columns.  Currently these always
differ by one.  Refactor aiColumn[] to be of type i16 instead of int.

FossilOrigin-Name: a106ce86cd4afd1f81603826de77df1fb25e9ab5
2013-10-22 18:01:40 +00:00
dan
a8dbadacee Fix handling of "DROP TABLE" commands when "PRAGMA defer_foreign_keys=1" is set.
FossilOrigin-Name: 27001356ed8201529b3f31d4313f2010f1b4e1b1
2013-10-12 15:12:43 +00:00
dan
8ff2d9561a When preparing an UPDATE statement, avoid generating VDBE code for those foreign key related actions and constraint checks that may be seen to be unnecessary by considering the subset of table columns potentially modified by the UPDATE.
FossilOrigin-Name: e940b5de49baa1d6a4cf859fbbc0e0df86ac5dbf
2013-09-05 18:40:29 +00:00
drh
648e264342 Add the "defer_foreign_keys" pragma and the SQLITE_DBSTATUS_DEFERRED_FKS
value for sqlite3_db_status().  This is a cherry-pick of a sequence of five
checkins in the sessions branch between [1d44e5d3c2] and [d39e65fe70].

FossilOrigin-Name: 527121ac3cdc96ac33ad975c227a6685a2f7e999
2013-07-11 15:03:32 +00:00
drh
d91c1a1768 Add extended error codes for constraint errors.
FossilOrigin-Name: 5461104668a49529577f21df97f6a0e7d8f0c679
2013-02-09 13:58:25 +00:00
drh
9148defa61 Enhance the error message for "foreign key mismatch" to include the names of
the child and parent tables.  Begin adding test cases for 
PRAGMA foreign_key_check.  Make sure PRAGMA foreign_key_check gets all
necessary table locks.

FossilOrigin-Name: 0f9963526c299757ff95c153fb05a67cddb6af28
2012-12-17 20:40:39 +00:00
drh
6c5b915fcb Prototype for PRAGMA that checks all foreign key constraints on a table.
FossilOrigin-Name: 01c980e9bbdf82e0b37667b6403c19ed8c73ee62
2012-12-17 16:46:37 +00:00
drh
580c8c1816 Veryquick passes all tests now.
FossilOrigin-Name: 7b96115e81deab0aa0472839cf787ba3f2fc64a7
2012-12-08 03:34:04 +00:00
drh
0a8a406e9b Some errors in veryquick resolved. Many more to go.
FossilOrigin-Name: 972443b4eb282d45507da06c75e2cd46dd72326b
2012-12-07 18:38:16 +00:00