atifiu commented on code in PR #57857:
URL: https://github.com/apache/doris/pull/57857#discussion_r2523598465
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java:
##########
@@ -463,16 +463,28 @@ public boolean registerTable(TableIf table) {
boolean result = true;
Table olapTable = (Table) table;
olapTable.setQualifiedDbName(fullQualifiedName);
- String tableName = olapTable.getName();
+ String tableName = olapTable.getName(); // stored (internal for temp)
+ String displayNameLower = null;
+ if (olapTable.isTemporary()) {
+ // derive display name (without session + #TEMP#) for reverse
lookup
+ String display = Util.getTempTableDisplayName(tableName);
+ displayNameLower = display.toLowerCase();
+ }
+ String lookupName = tableName;
if (Env.isStoredTableNamesLowerCase()) {
- tableName = tableName.toLowerCase();
+ lookupName = lookupName.toLowerCase();
}
- if (isTableExist(tableName)) {
+ if (isTableExist(lookupName)) {
result = false;
} else {
idToTable.put(olapTable.getId(), olapTable);
nameToTable.put(olapTable.getName(), olapTable);
- lowerCaseToTableName.put(tableName.toLowerCase(), tableName);
+ lowerCaseToTableName.put(lookupName.toLowerCase(), tableName);
+ // In stored-lowercase mode (1), user will query by display name.
+ // Add mapping from display lower-case name to internal temp name
so getTableNullable(display) succeeds.
+ if (olapTable.isTemporary() && displayNameLower != null) {
+ lowerCaseToTableName.put(displayNameLower, tableName);
Review Comment:
@morrySnow You're absolutely right! Thank you for catching that.
I've removed the display name mapping from `lowerCaseToTableName` in commit
6881e2d.
**The issue:** When a regular table and temp table have the same name (which
Doris allows), storing the temp display name would overwrite the regular
table's mapping, breaking regular table lookups.
**Why it still works:** The temp table resolution doesn't actually need the
display name mapping. The lookup flow already handles this correctly:
1. `getTableNullable("MyTable")` is called
2. It generates the temp inner name: `sessionId_#TEMP#_mytable`
3. It resolves this via `lowerCaseToTableName` (which maps the **internal**
name)
4. Looks up in `nameToTable` with the resolved internal name
5. If temp table exists, returns it; otherwise falls back to regular table
The fix simplifies `registerTable()` by removing the unnecessary display
name mapping logic entirely, avoiding the conflict you identified.
**Result:** Temp and regular tables with the same name can coexist
correctly, with temp tables taking precedence during queries.
--
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]