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

Only Use Hint to shard switch database,with not sqlParse #4806

Closed
phoema opened this issue Mar 17, 2020 · 5 comments
Closed

Only Use Hint to shard switch database,with not sqlParse #4806

phoema opened this issue Mar 17, 2020 · 5 comments

Comments

@phoema
Copy link

phoema commented Mar 17, 2020

Version
5.0.0-RC1-SNAPSHOT from master branch

Question

I used hint as a database rule.

But does the SQL statement still have to execute the sqlparse call? I just want to use hint to perform sub database operations. My statements have some associated retrieval or more complex statistical statements. Sqlparse is not well supported.

Of course, the release version may support it, but I don't want to witre many table config,Most tables only need to be sharding into databases

What can I do to tell shardingsphere not to parse it? Just access the specified database according to my hint rules.

or is there have some simple configuration writing methods to only shard with db and with not table?

my config is:
dataSources:
#names: master,test
master: !!com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/wise-master?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
username: root
password: J
#filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
#
filters: stat,wall,slf4j
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500;druid.stat.logSlowSql=true
test: !!com.alibaba.druid.pool.DruidDataSource
#type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/wise-test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
username: root
password: J
test2: !!com.alibaba.druid.pool.DruidDataSource
#type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/wise-test2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
username: root
password: J
shardingRule:
tables:
v_s_biz_fee: #TODO saas
databaseStrategy:
hint: #Hint
algorithmClassName: com.smarttree.manage.config.mybatis.HintShardingStrategy
v_s_official_notice: #TODO saas
databaseStrategy:
hint: #Hint
algorithmClassName: com.smarttree.manage.config.mybatis.HintShardingStrategy
act_ru_history_job:
databaseStrategy:
hint: #Hint
algorithmClassName: com.smarttree.manage.config.mybatis.HintShardingStrategy
act_ru_identitylink:
databaseStrategy:
hint: #Hint
algorithmClassName: com.smarttree.manage.config.mybatis.HintShardingStrategy
........
many tables with Hint
sys_area:
actualDataNodes: master.sys_area
databaseStrategy:
none: #Hint
sys_area_cn:
actualDataNodes: master.sys_area_cn
databaseStrategy:
none: #Hint
sys_tenant_info:
actualDataNodes: master.sys_tenant_info
databaseStrategy:
none: #Hint
sys_column_define:
actualDataNodes: master.sys_column_define
databaseStrategy:
none: #Hint
mst_cpc_info:
actualDataNodes: master.mst_cpc_info

defaultDataSourceName: master
defaultDatabaseStrategy:
hint: #Hint
algorithmClassName: com.smarttree.manage.config.mybatis.HintShardingStrategy
bindingTables:
- quartz_user_monitor,qrtz_triggers
- qrtz_job_details,qrtz_fired_triggers
props:
sql.show: true

@phoema
Copy link
Author

phoema commented Mar 17, 2020

#4478
@KomachiSion
KomachiSion commented 13 days ago:
I understand your problem. But if you do not config shardingRule, how can ShardingSphere judge which SQLs should be shared and which SQL not?
If you have hundreds of tables need to shard, you should config all of them to shardingRule, what ever you manual configuration files or program generate.

now i have 141 tables。。。。
is there any default config with many same loop config?

@terrymanu
Copy link
Member

Every SQL need to pass SQL parser engine.
The SQL parser engine should supported all SQL in future.
So I just close this issue and label it as won't fix

@kimmking
Copy link
Member

I used hint as a database rule.
But does the SQL statement still have to execute the sqlparse call?

Answer is yes.
Every sql will be parsed now.
Hint a ds as databaseShardingOnly=true, will avoid sql-rewrite phase, but parse phase is need.

@phoema
Copy link
Author

phoema commented Mar 17, 2020

The answer was timely
Thanks

if every table must be config,if not config then exception。
but my temp table name Alias will be not config in xml file.
like RES
it can be exception with 【Can not find owner from table.】
org.apache.shardingsphere.sql.parser.binder.segment.select.projection.engine.ProjectionsContextEngine

is this the same question with upper question ?

SELECT DISTINCT
RES.*
FROM
(
SELECT
SELF.*,
DEF.NAME_,
DEF.VERSION_
FROM
ACT_HI_PROCINST SELF
LEFT JOIN ACT_RE_PROCDEF DEF ON SELF.PROC_DEF_ID_ = DEF.ID_
WHERE
( 1 = 1 AND SELF.PROC_INST_ID_ = ? )
) RES
ORDER BY
RES.ID_ ASC
LIMIT ? OFFSET ?

@phoema
Copy link
Author

phoema commented Mar 17, 2020

@terrymanu @kimmking

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

No branches or pull requests

3 participants