<p dir="auto">If the original SQL is:</p>
<div class="highlight highlight-source-sql notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="SELECT t_account.* FROM t_account WHERE account_id=?"><pre class="notranslate"><span class="pl-k">SELECT</span> t_account.<span class="pl-k">*</span> <span class="pl-k">FROM</span> t_account <span class="pl-k">WHERE</span> account_id<span class="pl-k">=</span>?</pre></div>
<p dir="auto">The current rewrited SQL which is incorrect:</p>
<div class="highlight highlight-source-sql notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="SELECT `t_account`.col1, `t_account`.col2, `t_account`.col_n FROM t_account_0 WHERE account_id=?"><pre class="notranslate"><span class="pl-k">SELECT</span> <span class="pl-s"><span class="pl-pds">`</span>t_account<span class="pl-pds">`</span></span>.col1, <span class="pl-s"><span class="pl-pds">`</span>t_account<span class="pl-pds">`</span></span>.col2, <span class="pl-s"><span class="pl-pds">`</span>t_account<span class="pl-pds">`</span></span>.col_n <span class="pl-k">FROM</span> t_account_0 <span class="pl-k">WHERE</span> account_id<span class="pl-k">=</span>?</pre></div>
<p dir="auto">It should be rewrite to:</p>
<div class="highlight highlight-source-sql notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="SELECT `t_account_0`.col1, `t_account_0`.col2, `t_account_0`.col_n FROM t_account_0 WHERE account_id=?"><pre class="notranslate"><span class="pl-k">SELECT</span> <span class="pl-s"><span class="pl-pds">`</span>t_account_0<span class="pl-pds">`</span></span>.col1, <span class="pl-s"><span class="pl-pds">`</span>t_account_0<span class="pl-pds">`</span></span>.col2, <span class="pl-s"><span class="pl-pds">`</span>t_account_0<span class="pl-pds">`</span></span>.col_n <span class="pl-k">FROM</span> t_account_0 <span class="pl-k">WHERE</span> account_id<span class="pl-k">=</span>?</pre></div>
<p dir="auto">The owner of projection can not rewrite to sharded table name.</p>
<p dir="auto">The solution for now is adding alias for table, for example:</p>
<div class="highlight highlight-source-sql notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="SELECT a.* FROM t_account a WHERE account_id=?"><pre class="notranslate"><span class="pl-k">SELECT</span> a.<span class="pl-k">*</span> <span class="pl-k">FROM</span> t_account a <span class="pl-k">WHERE</span> account_id<span class="pl-k">=</span>?</pre></div>
<p dir="auto">It can rewrite correctly</p>
<div class="highlight highlight-source-sql notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="SELECT a.* FROM t_account_0 a WHERE account_id=?"><pre class="notranslate"><span class="pl-k">SELECT</span> a.<span class="pl-k">*</span> <span class="pl-k">FROM</span> t_account_0 a <span class="pl-k">WHERE</span> account_id<span class="pl-k">=</span>?</pre></div>
<p dir="auto">Please see <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="817019321" data-permission-text="Title is private" data-url="https://github.com/apache/shardingsphere/issues/9512" data-hovercard-type="pull_request" data-hovercard-url="/apache/shardingsphere/pull/9512/hovercard" href="https://github.com/apache/shardingsphere/pull/9512">#9512</a> to find commented test cases for this issue.</p>
<h2 dir="auto">Bug Report</h2>
<h1 dir="auto">this ‘s my sharding config</h1>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="sharding.jdbc.datasource.names=ds0,ds1,ds2
sharding.jdbc.datasource.ds0.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds0.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds0.url=jdbc:mysql://localhost:3306/ds0?serverTimezone=GMT%2B8`
sharding.jdbc.datasource.ds0.username=root
sharding.jdbc.datasource.ds0.password=root

sharding.jdbc.datasource.ds1.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds1.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds1.url=jdbc:mysql://localhost:3306/ds1?serverTimezone=GMT%2B8
sharding.jdbc.datasource.ds1.username=root
sharding.jdbc.datasource.ds1.password=root

sharding.jdbc.datasource.ds2.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds2.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds2.url=jdbc:mysql://localhost:3306/ds2?serverTimezone=GMT%2B8
sharding.jdbc.datasource.ds2.username=root
sharding.jdbc.datasource.ds2.password=root

sharding.jdbc.config.sharding.default-data-source-name=ds2
sharding.jdbc.config.sharding.default-database-strategy.inline.sharding-column=user_id
sharding.jdbc.config.sharding.default-database-strategy.inline.algorithm-expression=ds$-&gt;{user_id % 3}
sharding.jdbc.config.sharding.default-key-generator-class-name=liuxun.jpa.shard.config.SnowFlakeGenerator

sharding.jdbc.config.sharding.tables.t_order.actual-data-nodes=ds$-&gt;{0..2}.t_order$-&gt;{0..1}
sharding.jdbc.config.sharding.tables.t_order.table-strategy.inline.sharding-column=order_id
sharding.jdbc.config.sharding.tables.t_order.table-strategy.inline.algorithm-expression=t_order$-&gt;{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order.key-generator-column-name=order_id
sharding.jdbc.config.sharding.tables.t_order_item.actual-data-nodes=ds$-&gt;{0..2}.t_order_item$-&gt;{0..1}
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding-column=order_id
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item$-&gt;{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator-column-name=order_item_id
sharding.jdbc.config.sharding.binding-tables=t_order,t_order_item

sharding.jdbc.config.sharding.tables.t_user.actual-data-nodes=ds$-&gt;{0..2}.t_user$-&gt;{0..1}
sharding.jdbc.config.sharding.tables.t_user.table-strategy.inline.sharding-column=user_id
sharding.jdbc.config.sharding.tables.t_user.table-strategy.inline.algorithm-expression=t_user$-&gt;{user_id % 2}
sharding.jdbc.config.sharding.tables.t_user.key-generator-column-name=user_id

sharding.jdbc.config.sharding.tables.t_product.actual-data-nodes=ds$-&gt;{0..2}.t_product$-&gt;{0..1}
sharding.jdbc.config.sharding.tables.t_product.database-strategy.inline.sharding-column=product_id
sharding.jdbc.config.sharding.tables.t_product.database-strategy.inline.algorithm-expression=ds$-&gt;{product_id % 2}
sharding.jdbc.config.sharding.tables.t_product.table-strategy.inline.sharding-column=product_id
sharding.jdbc.config.sharding.tables.t_product.table-strategy.inline.algorithm-expression=t_product$-&gt;{product_id % 2}
sharding.jdbc.config.sharding.tables.t_product.key-generator-column-name=product_id

sharding.jdbc.config.sharding.props.sql.show=true
"><pre class="notranslate"><code class="notranslate">sharding.jdbc.datasource.names=ds0,ds1,ds2
sharding.jdbc.datasource.ds0.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds0.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds0.url=jdbc:mysql://localhost:3306/ds0?serverTimezone=GMT%2B8`
sharding.jdbc.datasource.ds0.username=root
sharding.jdbc.datasource.ds0.password=root

sharding.jdbc.datasource.ds1.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds1.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds1.url=jdbc:mysql://localhost:3306/ds1?serverTimezone=GMT%2B8
sharding.jdbc.datasource.ds1.username=root
sharding.jdbc.datasource.ds1.password=root

sharding.jdbc.datasource.ds2.type=org.apache.commons.dbcp.BasicDataSource
sharding.jdbc.datasource.ds2.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds2.url=jdbc:mysql://localhost:3306/ds2?serverTimezone=GMT%2B8
sharding.jdbc.datasource.ds2.username=root
sharding.jdbc.datasource.ds2.password=root

sharding.jdbc.config.sharding.default-data-source-name=ds2
sharding.jdbc.config.sharding.default-database-strategy.inline.sharding-column=user_id
sharding.jdbc.config.sharding.default-database-strategy.inline.algorithm-expression=ds$-&gt;{user_id % 3}
sharding.jdbc.config.sharding.default-key-generator-class-name=liuxun.jpa.shard.config.SnowFlakeGenerator

sharding.jdbc.config.sharding.tables.t_order.actual-data-nodes=ds$-&gt;{0..2}.t_order$-&gt;{0..1}
sharding.jdbc.config.sharding.tables.t_order.table-strategy.inline.sharding-column=order_id
sharding.jdbc.config.sharding.tables.t_order.table-strategy.inline.algorithm-expression=t_order$-&gt;{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order.key-generator-column-name=order_id
sharding.jdbc.config.sharding.tables.t_order_item.actual-data-nodes=ds$-&gt;{0..2}.t_order_item$-&gt;{0..1}
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding-column=order_id
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item$-&gt;{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator-column-name=order_item_id
sharding.jdbc.config.sharding.binding-tables=t_order,t_order_item

sharding.jdbc.config.sharding.tables.t_user.actual-data-nodes=ds$-&gt;{0..2}.t_user$-&gt;{0..1}
sharding.jdbc.config.sharding.tables.t_user.table-strategy.inline.sharding-column=user_id
sharding.jdbc.config.sharding.tables.t_user.table-strategy.inline.algorithm-expression=t_user$-&gt;{user_id % 2}
sharding.jdbc.config.sharding.tables.t_user.key-generator-column-name=user_id

sharding.jdbc.config.sharding.tables.t_product.actual-data-nodes=ds$-&gt;{0..2}.t_product$-&gt;{0..1}
sharding.jdbc.config.sharding.tables.t_product.database-strategy.inline.sharding-column=product_id
sharding.jdbc.config.sharding.tables.t_product.database-strategy.inline.algorithm-expression=ds$-&gt;{product_id % 2}
sharding.jdbc.config.sharding.tables.t_product.table-strategy.inline.sharding-column=product_id
sharding.jdbc.config.sharding.tables.t_product.table-strategy.inline.algorithm-expression=t_product$-&gt;{product_id % 2}
sharding.jdbc.config.sharding.tables.t_product.key-generator-column-name=product_id

sharding.jdbc.config.sharding.props.sql.show=true

</code></pre></div>
<p dir="auto">I have configured three database, each with two tables in each database including t_order , t_order_item, t_user and t_product. The default data source is ds0 but I have an error when querying orders based on the amount range.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="java.sql.SQLSyntaxErrorException: Table 'ds1.t_order_order_items' doesn't exist at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.13.jar:8.0.13] at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.13.jar:8.0.13] at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.13.jar:8.0.13] "><pre class="notranslate"><code class="notranslate">java.sql.SQLSyntaxErrorException: Table 'ds1.t_order_order_items' doesn't exist at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.13.jar:8.0.13] at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.13.jar:8.0.13] at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.13.jar:8.0.13] 
</code></pre></div>
<p dir="auto">How to solve it? This table is automatically generated by shading, and in the default data source ds2, .t_order_order_items</p>