aboutsummaryrefslogtreecommitdiff
path: root/src/resolve.c
diff options
context:
space:
mode:
authordrh <>2024-03-19 16:34:32 +0000
committerdrh <>2024-03-19 16:34:32 +0000
commite9feb0acfc4bd4fc86fbc7eaa160361bef3e4198 (patch)
tree182e45203fd3714319f5772a6479763b3fdcc7f7 /src/resolve.c
parentf891ef8d6111c8c8aa7de74bcd36aaf2f4569c47 (diff)
downloadsqlite-e9feb0acfc4bd4fc86fbc7eaa160361bef3e4198.tar.gz
sqlite-e9feb0acfc4bd4fc86fbc7eaa160361bef3e4198.zip
In the name resolver when SQLITE_ALLOW_ROWID_IN_INDEX is enabled, if there
are multiple views that might resolve to the "rowid" but only one real table, then use that one real table and ignore the views. FossilOrigin-Name: 8fcea4cdfc89dd78eca5e7f62aa31aff0e296f41e79349d3af1cc3a2bc4d77c6
Diffstat (limited to 'src/resolve.c')
-rw-r--r--src/resolve.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/resolve.c b/src/resolve.c
index c2957a870..297193610 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -469,8 +469,37 @@ static int lookupName(
}
}
if( 0==cnt && VisibleRowid(pTab) ){
+ /* pTab is a potential ROWID match. Keep track of it and match
+ ** the ROWID later if that seems appropriate. (Search for "cntTab"
+ ** to find related code.) Only allow a ROWID match if there is
+ ** a single ROWID match candidate.
+ */
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
+ /* In SQLITE_ALLOW_ROWID_IN_VIEW mode, allow a ROWID match
+ ** if there is a single VIEW candidate or if there is a single
+ ** non-VIEW candidate plus multiple VIEW candidates. In other
+ ** words non-VIEW candidate terms take precedence over VIEWs.
+ */
+ if( cntTab==0
+ || (cntTab==1
+ && ALWAYS(pMatch!=0)
+ && ALWAYS(pMatch->pTab!=0)
+ && (pMatch->pTab->tabFlags & TF_Ephemeral)!=0
+ && (pTab->tabFlags & TF_Ephemeral)==0)
+ ){
+ cntTab = 1;
+ pMatch = pItem;
+ }else{
+ cntTab++;
+ }
+#else
+ /* The (much more common) non-SQLITE_ALLOW_ROWID_IN_VIEW case is
+ ** simpler since we require exactly one candidate, which will
+ ** always be a non-VIEW
+ */
cntTab++;
pMatch = pItem;
+#endif
}
}
if( pMatch ){