shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

not support count if, database will be the default , not the true

Open trojanliu opened this issue 7 years ago • 8 comments

i has two databases; like 'comon' and 'user'; 'comon' as the default database; table 'tx_user' is in 'user' database.

SELECT count(IF(sex = 1 , TRUE , NULL)) AS maleCount FROM tx_user; can be explain to comon.tx_user;

trojanliu avatar Mar 28 '19 08:03 trojanliu

@trojanliu thanks for you issue, is 'user' database for sharding ? please show your sharding rule.

codefairy08 avatar Mar 29 '19 08:03 codefairy08

<sharding:data-source id="myDataSource"> <sharding:sharding-rule data-source-names="common,user" default-data-source-name="common" default-database-strategy-ref="noneStrategy" default-table-strategy-ref="noneStrategy"> <sharding:table-rules> <sharding:table-rule logic-table="tx_user" actual-data-nodes="user.tx_user" generate-key-column-name="uid"/> </sharding:table-rules> </sharding:sharding-rule> <sharding:props> <prop key="sql.show">${hibernate.show_sql}</prop> <prop key="executor.size">2</prop> </sharding:props> </sharding:data-source>

trojanliu avatar Mar 29 '19 16:03 trojanliu

<sharding:table-rule logic-table="tx_user" actual-data-nodes="user.tx_user" generate-key-column-name="uid"/>

trojanliu avatar Mar 29 '19 16:03 trojanliu

tx_user is a single table. no databases rule , no tables rule .

trojanliu avatar Apr 01 '19 02:04 trojanliu

@trojanliu which shardingsphere version do you use? have a try using dev branch code , i use sharding-spring-namespace-mybatis-example , shardingsphere code is the lastest, result of routing is correct.See the following figures for the results. image image image

codefairy08 avatar Apr 01 '19 08:04 codefairy08

i use 3.1.0. dev branch code is ok? i try it later .

trojanliu avatar Apr 01 '19 10:04 trojanliu

use this version 4.0.0-RC1-SNAPSHOT, compile it by yourself using source code,,just mvn clean install in root dir of project

codefairy08 avatar Apr 01 '19 10:04 codefairy08

image

aaaaaaaaaaa

IN VERSION 3.1.0

if sql is 'SELECT count(IF(sex = 1 , TRUE , NULL)) AS maleCount FROM tx_user;'

it will parsing stop at if.
AND tablename is not parsing, so it use the default database;

trojanliu avatar Apr 08 '19 05:04 trojanliu