Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table的 alias在查询里面忘记添加了 #10

Open
steven0lisa opened this issue Jul 17, 2017 · 0 comments
Open

table的 alias在查询里面忘记添加了 #10

steven0lisa opened this issue Jul 17, 2017 · 0 comments

Comments

@steven0lisa
Copy link

下面是示例语句

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。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant