shashankrnr32 opened a new issue, #24517:
URL: https://github.com/apache/shardingsphere/issues/24517
## Bug Report
Thanks team for creating this project. Noticed an issue with SQL Parser &
Rewriting engine with respect to information_schema tables. Noticed that
information_schema support is still in experimental stage.
If this issue is already reported or is already picked up to be fixed,
please feel free to close the issue and point it to the right issue/PR in the
project. Also, feel free to correct me in case i have used any of the terms
wrong w.r.t this project.
### Which version of ShardingSphere did you use?
5.2.1
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-JDBC (From the Spring Boot Start
### Expected behavior
Executing Query on Information Schema tables results in rewriting of SQL
which removes `owner` from the query and executes it with just the value
**Sample Query:**
Logical Query
```
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, COLUMN_KEY, EXTRA,
COLLATION_NAME, ORDINAL_POSITION FROM information_schema.columns WHERE
TABLE_SCHEMA=? AND TABLE_NAME IN ('columns', 'schema_data_statistics') ORDER BY
ORDINAL_POSITION
```
After SQL Rewrite
```
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, COLUMN_KEY, EXTRA,
COLLATION_NAME, ORDINAL_POSITION FROM columns WHERE TABLE_SCHEMA=? AND
TABLE_NAME IN ('columns', 'schema_data_statistics') ORDER BY ORDINAL_POSITION
```
The following error is seen
```
Table 'test_table.columns' doesn't exist
```
### Actual behavior
The actual expected behavior should be any one of these
1. The `owner` should be added to the query in case of information_schema
2. The SQL parser should consider the periods (`.`) in the table name as
valid.
### Reason analyze (If you can)
The SQLStatement Object parsed has this as the Table Segment when the above
query is parsed by the engine.
```
SimpleTableSegment(tableName=TableNameSegment(startIndex=119,
stopIndex=125,
identifier=IdentifierValue(value=columns,
quoteCharacter=NONE)),
owner=Optional[
OwnerSegment(startIndex=100,
stopIndex=117,
identifier=IdentifierValue(value=information_schema,
quoteCharacter=NONE),
owner=Optional.empty)
]
```
Also when parsing this, the engine wrongly identifies `information_schema`
as a database. (See TablesContext object below)
TablesContext Object of the same above query
```
TablesContext(tables=[
SimpleTableSegment(tableName=TableNameSegment(startIndex=119,
stopIndex=125,
identifier=IdentifierValue(value=columns,
quoteCharacter=NONE)),
owner=Optional[
OwnerSegment(startIndex=100,
stopIndex=117,
identifier=IdentifierValue(value=information_schema,
quoteCharacter=NONE),
owner=Optional.empty)
],
alias=Optional.empty)
],
tableNames=[
columns
],
schemaNames=[
information_schema
],
databaseNames=[
information_schema
],
subqueryTables={
})
```
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule
configuration, when exception occur etc
Provided above.
### Example codes for reproduce this issue (such as a github link).
NA
--
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]