OrConditionFiller#getTableName error
Bug Report
For English only, other languages will not accept.
Before report a bug, make sure you have:
- Searched open and closed GitHub issues.
- Read documentation: ShardingSphere Doc.
Please pay attention on issues you submitted, because we maybe need more details. If no response more than 7 days and we cannot reproduce it on current information, we will close it.
Please answer these questions before submitting your issue. Thanks!
Which version of ShardingSphere did you use?
4.0.0-RC2
Which project did you use? Sharding-JDBC or Sharding-Proxy?
Sharding-JDBC
Expected behavior
sql like:
select id customerId, entity_card_num entityCardNum, mobile, NAME
from customer where company_id = ? and id not in (
SELECT distinct customer_id
FROM customer_account_change_record cacr inner join customer c on cacr.company_id = c.company_id and c.id =
cacr.customer_id and cacr.company_id = ?
WHERE cacr.created between ? and ?
and cacr.company_id = ?
and cacr.card_type = 1
) and enabled_status = 1
order by created desc
limit ?,?
ConditionSegment(name:created, owner:cacr, operator:BETWEEN)
Actual behavior
getTableName will return 'customer' not 'customer_account_change_record'
Reason analyze (If you can)
private String getTableName(final ShardingTableMetaData shardingTableMetaData, final ShardingRule shardingRule, final Tables tables, final ConditionSegment conditionSegment) {
Collection<String> shardingLogicTableNames = shardingRule.getShardingLogicTableNames(tables.getTableNames());
if (tables.isSingleTable() || tables.isSameTable() || 1 == shardingLogicTableNames.size() || shardingRule.isAllBindingTables(shardingLogicTableNames)) {
return tables.getSingleTableName();
}
if (conditionSegment.getColumn().getOwner().isPresent()) {
Optional<Table> table = tables.find(conditionSegment.getColumn().getOwner().get());
return table.isPresent() ? table.get().getName() : "";
} else {
return getTableNameFromMetaData(shardingTableMetaData, tables, conditionSegment.getColumn().getName());
}
}
match the if condition 1 == shardingLogicTableNames.size() then direct return the first table name
Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
Example codes for reproduce this issue (such as a github link).
if tables have more than one, why 1 == shardingLogicTableNames.size() return the first table name?
“1 == shardingLogicTableNames.size() return the first table name": the outer query just has one table, the column just belong to this table, ignore subquery condition use its table, it cause parsing wrong table name please show your sharding rule thanks
please show your sharding rule sharding rule is
customer_account_change_record:
tableStrategy:
standard:
shardingColumn: created
precise-algorithm-class-name: xxx.TimeSharding$PreciseTimeSharding
range-algorithm-class-name: xxx.TimeSharding$RangeTimeSharding
customer is binding table with customer_account_change_record?or customer is not sharding table?
customer is binding table with customer_account_change_record?
no. customer is single table, and customer_account_change_record is multi talbe
customer is in default data source ? customer_account_change_record is in sharding da.ta source? sharding column is in subquery condition,sharding condition does not fill into SelectStatement
customer and customer_account_change_record all use shardingDataSource.
The SQL has subquery in where condition, it does not always route in one sharding datasource, the SQL is not supported now