aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2023-03-16 10:17:30 +0000
committerdrh <>2023-03-16 10:17:30 +0000
commit7d5a5491215eb48acba22a81067aae2661bb2fd6 (patch)
tree8680f1df9f8c4decf1f2dc4112d2db3520b48b39 /src
parent5531316dd030b320c5653454bc2dcec23bf261b2 (diff)
downloadsqlite-7d5a5491215eb48acba22a81067aae2661bb2fd6.tar.gz
sqlite-7d5a5491215eb48acba22a81067aae2661bb2fd6.zip
Do not use the one-pass optimization on an UPDATE if there is a subquery
in the WHERE clause, since if the subquery is hidden behind a short-circuit operator, the subquery might not be evaluated until after one or more rows have been updated. Fix for the problem reported by [forum:/forumpost/0007d1fdb1|forum post 0007d1fdb1]. This is the same problem that was fixed by [73f0036f045bf371] only for UPDATE instead of DELETE. FossilOrigin-Name: 2c56b984a0bd3be5ec326a2109ea7b8f1d4ef63c8fc325caac9663cf2479eaff
Diffstat (limited to 'src')
-rw-r--r--src/update.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/update.c b/src/update.c
index a4e57d1d4..bd1ddb1a3 100644
--- a/src/update.c
+++ b/src/update.c
@@ -727,12 +727,22 @@ void sqlite3Update(
/* Begin the database scan.
**
** Do not consider a single-pass strategy for a multi-row update if
- ** there are any triggers or foreign keys to process, or rows may
- ** be deleted as a result of REPLACE conflict handling. Any of these
- ** things might disturb a cursor being used to scan through the table
- ** or index, causing a single-pass approach to malfunction. */
+ ** there is anything that might disrupt the cursor being used to do
+ ** the UPDATE:
+ ** (1) This is a nested UPDATE
+ ** (2) There are triggers
+ ** (3) There are FOREIGN KEY constraints
+ ** (4) There are REPLACE conflict handlers
+ ** (5) There are subqueries in the WHERE clause
+ */
flags = WHERE_ONEPASS_DESIRED;
- if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){
+ if( !pParse->nested
+ && !pTrigger
+ && !hasFK
+ && !chngKey
+ && !bReplace
+ && (sNC.ncFlags & NC_Subquery)==0
+ ){
flags |= WHERE_ONEPASS_MULTIROW;
}
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0,0,0,flags,iIdxCur);