table的 alias在查询里面忘记添加了
steven0lisa opened this issue · comments
下面是示例语句
select orders0_.id as id1_5_, orders0_.create_time as create_t2_5_, orders0_.update_time as update_t3_5_, orders0_.delivered as delivere4_5_, orders0_.mch_order_no as mch_orde5_5_, orders0_.merchant_id as merchant6_5_, orders0_.num as num7_5_, orders0_.order_no as order_no8_5_, orders0_.paid as paid9_5_, orders0_.product_id as product10_5_ from orders orders0_
where orders0_.merchant_id=‘HsPSlXcm37rkzMNHti4' and orders0_.mch_order_no='20170717163649132' limit 1
解析后分发到全部节点的语句变成了
SELECT orders0_.id AS id1_5_, orders0_.create_time AS create_t2_5_, orders0_.update_time AS update_t3_5_, orders0_.delivered AS delivere4_5_, orders0_.mch_order_no AS mch_orde5_5_
, orders0_.merchant_id AS merchant6_5_, orders0_.num AS num7_5_, orders0_.order_no AS order_no8_5_, orders0_.paid AS paid9_5_, orders0_.product_id AS product10_5_
FROM orders_1
WHERE orders0_.merchant_id = HsPSlXcm37rkzMNHti4
LIMIT 10000
from后面漏了 orders0_
这个。
修复方法:
//io.mycat.route.parser.druid.impl.DruidSelectParser
//more code ...
if(rrs.isDistTable()){
SQLTableSource from = mysqlSelectQuery.getFrom();
for (RouteResultsetNode node : rrs.getNodes()) {
SQLIdentifierExpr sqlIdentifierExpr = new SQLIdentifierExpr();
sqlIdentifierExpr.setParent(from);
sqlIdentifierExpr.setName(node.getSubTableName());
//这句漏传了一个参数,导致alias丢失
//SQLExprTableSource from2 = new SQLExprTableSource(sqlIdentifierExpr);
//更正为下面语句即可
SQLExprTableSource from2 = new SQLExprTableSource(sqlIdentifierExpr, from.getAlias());
mysqlSelectQuery.setFrom(from2);
node.setStatement(stmt.toString());
}
}
目前测试过,1.6.5
1.7
都存在这个问题,而这种alias常被用于hibernate。