Doris-Breakwater commented on issue #70463:
URL: https://github.com/apache/doris/issues/70463#issuecomment-6788858301

   Source-level triage: this report is supported by the code at 
`9fb3e3a2a13f972a62cb999d5599fc8e8f17f306`. The failure is in FE/Nereids 
database-name resolution. The supplied revision and SQL are sufficient to 
identify the faulty path; this analysis does not include a live-cluster 
reproduction or a tested patch.
   
   Verified facts:
   
   - The 
[grammar](https://github.com/apache/doris/blob/9fb3e3a2a13f972a62cb999d5599fc8e8f17f306/fe/fe-sql-parser/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4#L602)
 accepts `multipartIdentifier` for all five database clauses. That rule permits 
arbitrarily many components, so the visitors must validate the supported arity.
   - In `LogicalPlanBuilder`, `visitShowEncryptKeys` (line 2901), 
`visitShowSmallFiles` (6768), `visitShowDynamicPartition` (7357), and 
[visitShowDelete](https://github.com/apache/doris/blob/9fb3e3a2a13f972a62cb999d5599fc8e8f17f306/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java#L7756)
 all retain only `nameParts.get(0)`, without checking length or catalog. Thus 
`internal.db1` becomes `internal`, and `a.b.c` becomes `a`. The command 
implementations use internal metadata, with `SHOW ENCRYPTKEYS` additionally 
checking the current catalog. They cannot recover the discarded qualifier. 
Depending on database existence and privileges, the result can be an error or 
metadata from the wrong database.
   - 
[visitShowColumns](https://github.com/apache/doris/blob/9fb3e3a2a13f972a62cb999d5599fc8e8f17f306/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java#L7675)
 instead passes `ctx.database.getText()`. 
[ShowColumnsCommand.validate](https://github.com/apache/doris/blob/9fb3e3a2a13f972a62cb999d5599fc8e8f17f306/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowColumnsCommand.java#L103)
 assigns that entire string with `tableNameInfo.setDb(databaseName)`. 
`TableNameInfo.analyze` fills missing catalog/database defaults but does not 
split this field. The normal execution path subsequently looks up the literal 
database name `internal.db1`, explaining the reported error.
   
   Suggested fix direction for the proposed PR:
   
   1. Resolve database clauses through parsed identifier components. Accept one 
component as the database and two as catalog/database; reject database clauses 
with three or more components before lookup. Preserve omitted-database behavior 
and quoted identifiers rather than splitting raw text on dots.
   2. For the four internal-only commands, validate an explicit catalog before 
discarding it, accepting `internal` and rejecting other catalogs. 
[visitShowConvertLsc](https://github.com/apache/doris/blob/9fb3e3a2a13f972a62cb999d5599fc8e8f17f306/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java#L8030)
 provides a nearby arity/catalog-validation example. `visitShowFunctions` 
handles two components but does not validate the catalog, so copying it alone 
would leave that requirement unmet.
   3. For `SHOW COLUMNS`, carry both resolved catalog and database into 
`TableNameInfo` before validation and privilege checks. Its execution already 
supports catalog lookup. Preserve existing behavior for a fully qualified table 
operand and establish precedence when both the table operand and the separate 
database clause contain qualifiers.
   
   One additional boundary needs explicit coverage: 
[ShowEncryptKeysCommand.doRun](https://github.com/apache/doris/blob/9fb3e3a2a13f972a62cb999d5599fc8e8f17f306/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowEncryptKeysCommand.java#L83)
 rejects an external session default catalog and uses 
`ctx.getCurrentCatalog()`. Merely changing the visitor to return `db1` will not 
make `FROM internal.db1` work while the session is switched to an external 
catalog. The PR should define and test the intended behavior here.
   
   Next validation: add parser/command tests and SQL regression coverage for 
all five statements, including `FROM`/`IN`, omitted and unqualified databases, 
explicit `internal.db1`, non-internal qualifiers, three-component database 
clauses, and quoted names. Include a database named after the first component 
so tests detect silent misrouting, not just errors. For `SHOW COLUMNS`, cover 
external catalogs, qualified table operands, `FULL`/`FIELDS`, and both `LIKE` 
and `WHERE` execution paths.
   
   No additional logs or profile are needed for this initial diagnosis. Still 
unverified: runtime results for that matrix, the first affected release, and 
backport scope. Those require test output and revision/release checks; the 
supplied evidence establishes the defect at the reported master commit only. 
Suggested component: FE / Nereids parser.
   
   Breakwater-GitHub-Analysis-Slot: slot_c5d563d6bb9c
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to