Name resolution and "*" wildcard expansion for parenthesized FROM clauses

seems to work the same as PG.  The code is chaos, however, and needs some
cleanup.

FossilOrigin-Name: 6f9c0b07aadc5189c65c3ee4e6938aac10fc0d98f1cb06980f5e5d7b0308f237
This commit is contained in:
drh 2022-05-02 19:59:03 +00:00
parent 85f93850f7
commit 72d620bdb1
6 changed files with 27 additions and 11 deletions

View File

@ -1,5 +1,5 @@
C Merge\sthe\slatest\strunk\sfixes\sand\senhancements\sinto\sthe\sright-join\sbranch.
D 2022-05-02T15:10:38.366
C Name\sresolution\sand\s"*"\swildcard\sexpansion\sfor\sparenthesized\sFROM\sclauses\nseems\sto\swork\sthe\ssame\sas\sPG.\s\sThe\scode\sis\schaos,\showever,\sand\sneeds\ssome\ncleanup.
D 2022-05-02T19:59:03.190
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -504,7 +504,7 @@ F src/date.c 15082566229d4b1e5f24fdb490bf9bcc68824b911d70e3573ef075a1b9e2d26f
F src/dbpage.c 90661a87e1db8bfbc8d2ebbdcd3749651ddb287c555c07a28fb17c7c591ffb68
F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d
F src/delete.c a8e844af211a48b13b5b358be77a12c860c6a557c21990ad51a548e2536500ce
F src/expr.c efa37babe35dcf79933beb9df3aee0c6a2f60ac56645773c73c866fd9894d938
F src/expr.c 495ff0219a5aa2161d33e10f20912ce7dcd55fc13459e0dc48abae52934bfadf
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c d965ede15d8360c09ed59348940649ee647b192e784466837d7aefa836d1d91e
F src/func.c a3407a6fbb0d4088d8d502e46f0ace63e0aeae7467ae23a9ca9815bbf9239761
@ -553,12 +553,12 @@ F src/printf.c 512574910a45341c8ad244bd3d4939968ebdfde215645b676fff01cc46e90757
F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c
F src/resolve.c b14bf8a4a1e3cb01eefc48a7e4129b15bb6a18b56d16dd4eca676586464337d0
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
F src/select.c b319bfcdf6c06841312f7e98c71f384d775f20138760855b8489aa6a05a70e72
F src/select.c 41a371b0256c38e258a4265d55fe55e7cd6a197c586647faee9924341ee06b4f
F src/shell.c.in ae0a6fae983caac6f8c824733f0599dfdf7b3a7e8efdef3cb5e3ab2e457ffc35
F src/sqlite.h.in 2a35f62185eb5e7ecc64a2f68442b538ce9be74f80f28a00abc24837edcf1c17
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h f49e28c25bd941e79794db5415fdf7b202deb3bc072ed6f1ed273d578703684e
F src/sqliteInt.h 3aaaf14804c77feadfd2ee241bb7e9ca4aa5be5cacddab8f9f7f2e8190a0c5b2
F src/sqliteInt.h 73faf6b2222f70f7777624a08af799cc20822d4cc578306b1316088dddd47736
F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657
F src/status.c 4a3da6d77eeb3531cb0dbdf7047772a2a1b99f98c69e90ce009c75fe6328b2c0
F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
@ -618,7 +618,7 @@ F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c
F src/tokenize.c a38f52058b517929e264094abd0b5fd1e8e145a1aa43bc6f6a72ae5218f96c98
F src/treeview.c 5c2a8d3bc6c91c3108cc63beba7b04ec5f2fdaefd1a2dc534fb4ef8f4a1d588a
F src/treeview.c c91eee716ac380fddd74c4cf3914562080f8d520a0e557d824d5919e131ac6e5
F src/trigger.c 372ada38f667c6823a3db15749eb668338e65c793394e55a37e56a489f2d1b55
F src/update.c 2cfaded82ca80ff56afb8c3ae5e88284e0824bfd86119827cc22481959f96f92
F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937
@ -1952,8 +1952,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 9cba3ce577e442f83d7a2d6926e38ffe6bc45953c88ecdd384f3455890303cce cc458317bd77046c4328715ae9e3409f3f4cd422a01162cb33405ef3a142b0a3
R 8c6adc25dedee0141892e4be83329645
P afbcf075c1e09ae064c7b16e63501cd1d374711812664aef76bd35d02d64a2b6
R 555aead77d8cae1693b8c4f6bc8f3e4c
U drh
Z 8ddd04e8896d9f6869b3f2d45984a6f1
Z 87ce52a531a5370a01dfeb75577a427b
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
afbcf075c1e09ae064c7b16e63501cd1d374711812664aef76bd35d02d64a2b6
6f9c0b07aadc5189c65c3ee4e6938aac10fc0d98f1cb06980f5e5d7b0308f237

View File

@ -1635,6 +1635,7 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, const ExprList *p, int flags){
pItem->bUsed = pOldItem->bUsed;
pItem->bUsingTerm = pOldItem->bUsingTerm;
pItem->bSorterRef = pOldItem->bSorterRef;
pItem->bNoExpand = pOldItem->bNoExpand;
pItem->u = pOldItem->u;
}
return pNew;

View File

@ -2231,6 +2231,9 @@ int sqlite3ColumnsFromExprList(
}
pCol->zCnName = zName;
pCol->hName = sqlite3StrIHash(zName);
if( pX->bNoExpand ){
pCol->colFlags |= COLFLAG_NOEXPAND;
}
sqlite3ColumnPropertiesFromName(0, pCol);
if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
sqlite3OomFault(db);
@ -5822,6 +5825,7 @@ static int selectExpander(Walker *pWalker, Select *p){
char *zTabName; /* AS name for this data source */
const char *zSchemaName = 0; /* Schema name for this data source */
int iDb; /* Schema index for this data src */
IdList *pUsing; /* USING clause for this join */
if( (zTabName = pFrom->zAlias)==0 ){
zTabName = pTab->zName;
@ -5846,7 +5850,7 @@ static int selectExpander(Walker *pWalker, Select *p){
&& (selFlags & SF_NestedFrom)!=0
){
int ii;
IdList *pUsing = pFrom[1].u3.pUsing;
pUsing = pFrom[1].u3.pUsing;
for(ii=0; ii<pUsing->nId; ii++){
const char *zUName = pUsing->a[ii].zName;
pRight = sqlite3Expr(db, TK_ID, zUName);
@ -5859,6 +5863,8 @@ static int selectExpander(Walker *pWalker, Select *p){
pX->bUsingTerm = 1;
}
}
}else{
pUsing = 0;
}
for(j=0; j<pTab->nCol; j++){
char *zName = pTab->aCol[j].zCnName;
@ -5938,6 +5944,13 @@ static int selectExpander(Walker *pWalker, Select *p){
testcase( pX->zEName==0 );
}
pX->eEName = ENAME_TAB;
if( (pFrom->fg.isUsing
&& sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0)
|| (pUsing && sqlite3IdListIndex(pUsing, zName)>=0)
|| (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
){
pX->bNoExpand = 1;
}
}else if( longNames ){
pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
pX->eEName = ENAME_NAME;

View File

@ -3008,6 +3008,7 @@ struct ExprList {
unsigned bNulls :1; /* True if explicit "NULLS FIRST/LAST" */
unsigned bUsed :1; /* This column used in a SF_NestedFrom subquery */
unsigned bUsingTerm:1; /* Term from the USING clause of a NestedFrom */
unsigned bNoExpand: 1;
union {
struct { /* Used by any ExprList other than Parse.pConsExpr */
u16 iOrderByCol; /* For ORDER BY, column number in result set */

View File

@ -882,6 +882,7 @@ void sqlite3TreeViewBareExprList(
fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
if( pList->a[i].bUsed ) fprintf(stdout, "(used) ");
if( pList->a[i].bUsingTerm ) fprintf(stdout, "(USING-term) ");
if( pList->a[i].bNoExpand ) fprintf(stdout, "(NoExpand) ");
break;
case ENAME_SPAN:
fprintf(stdout, "SPAN(\"%s\") ", zName);