[
https://issues.apache.org/jira/browse/CALCITE-3621?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Lei Jiang updated CALCITE-3621:
-------------------------------
Description:
JDBC adapter can't push down sort to DB
{code:java}
select ename from scott.emp order by empno
{code}
{code:java}
PLAN=EnumerableSort(sort0=[$1], dir0=[ASC])
JdbcToEnumerableConverter
JdbcProject(ENAME=[$1], EMPNO=[$0])
JdbcTableScan(table=[[SCOTT, EMP]])
{code}
It should be:
{code:java}
PLAN=JdbcToEnumerableConverter
JdbcSort(sort0=[$1], dir0=[ASC])
JdbcProject(ENAME=[$1], EMPNO=[$0])
JdbcTableScan(table=[[SCOTT, EMP]])
{code}
I think the root cause is JdbcSortRule, it convert input's trait to "JDBC,
{color:#ff0000}[1]{color}". that is, input's relset will add a "JDBC, [1]"
subset. But there is nothing rule can convert that input to a rel with "JDBC,
{color:#ff0000}[1]{color}", so EnumerableSort win.
{code:java}
public RelNode convert(Sort sort, boolean convertInputTraits) {
final RelTraitSet traitSet = sort.getTraitSet().replace(out);
final RelNode input;
if (convertInputTraits) {
input = convert(sort.getInput(), traitSet);
} else {
input = sort.getInput();
}
return new JdbcSort(sort.getCluster(), traitSet,
input, sort.getCollation(), sort.offset, sort.fetch);
}
{code}
This is my a part of change: convert input's trait to "JDBC, []"
{code:java}
public RelNode convert(Sort sort, boolean convertInputTraits) {
final RelTraitSet traitSet = sort.getTraitSet().replace(out);
//update again
final RelTraitSet inputTraitSet = sort.getInput().getTraitSet().replace(out);
final RelNode input;
if (convertInputTraits) {
//update
input = convert(sort.getInput(), inputTraitSet);
} else {
input = sort.getInput();
}
return new JdbcSort(sort.getCluster(), traitSet,
input, sort.getCollation(), sort.offset, sort.fetch);
}
{code}
By the way, when we switch "_calcite.enable.enumerable_" to "_false_" without
this change, this case will be failed.
{code:java}
java.sql.SQLException: Error while executing SQL "explain plan for select ename
from scott.emp
order by empno": There are not enough rules to produce a node with desired
properties: convention=ENUMERABLE, sort=[1].
Missing conversion is JdbcTableScan[sort: [] -> [0]]
There is 1 empty subset: rel#34:Subset#0.JDBC.SCOTT.[0], the relevant part of
the original plan is as follows
0:JdbcTableScan(table=[[SCOTT, EMP]])
{code}
was:
JDBC adapter can't push down sort to DB
{code:java}
select ename from scott.emp order by empno
{code}
{code:java}
PLAN=EnumerableSort(sort0=[$1], dir0=[ASC])
JdbcToEnumerableConverter
JdbcProject(ENAME=[$1], EMPNO=[$0])
JdbcTableScan(table=[[SCOTT, EMP]])
{code}
It should be:
{code:java}
PLAN=JdbcToEnumerableConverter
JdbcSort(sort0=[$1], dir0=[ASC])
JdbcProject(ENAME=[$1], EMPNO=[$0])
JdbcTableScan(table=[[SCOTT, EMP]])
{code}
I think the root cause is JdbcSortRule, it convert input's trait to "JDBC,
{color:#ff0000}[1]{color}". that is, input's relset will add a "JDBC, [1]"
subset. But there is nothing rule can convert that input to a rel with "JDBC,
{color:#ff0000}[1]{color}", so EnumerableSort win.
{code:java}
public RelNode convert(Sort sort, boolean convertInputTraits) {
final RelTraitSet traitSet = sort.getTraitSet().replace(out);
final RelNode input;
if (convertInputTraits) {
input = convert(sort.getInput(), traitSet);
} else {
input = sort.getInput();
}
return new JdbcSort(sort.getCluster(), traitSet,
input, sort.getCollation(), sort.offset, sort.fetch);
}
{code}
This is my a part of change: convert input's trait to "JDBC, []"
{code:java}
public RelNode convert(Sort sort, boolean convertInputTraits) {
final RelTraitSet traitSet = sort.getTraitSet().replace(out);
//update again
final RelTraitSet inputTraitSet = sort.getInput().getTraitSet().replace(out);
final RelNode input;
if (convertInputTraits) {
//update
input = convert(sort.getInput(), inputTraitSet);
} else {
input = sort.getInput();
}
return new JdbcSort(sort.getCluster(), traitSet,
input, sort.getCollation(), sort.offset, sort.fetch);
}
{code}
> JDBC adapter can't push down sort to DB
> ---------------------------------------
>
> Key: CALCITE-3621
> URL: https://issues.apache.org/jira/browse/CALCITE-3621
> Project: Calcite
> Issue Type: Bug
> Components: jdbc-adapter
> Affects Versions: 1.21.0
> Reporter: Lei Jiang
> Assignee: Lei Jiang
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.22.0
>
> Time Spent: 2h 20m
> Remaining Estimate: 0h
>
> JDBC adapter can't push down sort to DB
> {code:java}
> select ename from scott.emp order by empno
> {code}
> {code:java}
> PLAN=EnumerableSort(sort0=[$1], dir0=[ASC])
> JdbcToEnumerableConverter
> JdbcProject(ENAME=[$1], EMPNO=[$0])
> JdbcTableScan(table=[[SCOTT, EMP]])
> {code}
> It should be:
> {code:java}
> PLAN=JdbcToEnumerableConverter
> JdbcSort(sort0=[$1], dir0=[ASC])
> JdbcProject(ENAME=[$1], EMPNO=[$0])
> JdbcTableScan(table=[[SCOTT, EMP]])
> {code}
> I think the root cause is JdbcSortRule, it convert input's trait to "JDBC,
> {color:#ff0000}[1]{color}". that is, input's relset will add a "JDBC, [1]"
> subset. But there is nothing rule can convert that input to a rel with "JDBC,
> {color:#ff0000}[1]{color}", so EnumerableSort win.
> {code:java}
> public RelNode convert(Sort sort, boolean convertInputTraits) {
> final RelTraitSet traitSet = sort.getTraitSet().replace(out);
> final RelNode input;
> if (convertInputTraits) {
> input = convert(sort.getInput(), traitSet);
> } else {
> input = sort.getInput();
> }
> return new JdbcSort(sort.getCluster(), traitSet,
> input, sort.getCollation(), sort.offset, sort.fetch);
> }
> {code}
> This is my a part of change: convert input's trait to "JDBC, []"
> {code:java}
> public RelNode convert(Sort sort, boolean convertInputTraits) {
> final RelTraitSet traitSet = sort.getTraitSet().replace(out);
> //update again
> final RelTraitSet inputTraitSet =
> sort.getInput().getTraitSet().replace(out);
> final RelNode input;
> if (convertInputTraits) {
> //update
> input = convert(sort.getInput(), inputTraitSet);
> } else {
> input = sort.getInput();
> }
> return new JdbcSort(sort.getCluster(), traitSet,
> input, sort.getCollation(), sort.offset, sort.fetch);
> }
> {code}
>
> By the way, when we switch "_calcite.enable.enumerable_" to "_false_" without
> this change, this case will be failed.
> {code:java}
> java.sql.SQLException: Error while executing SQL "explain plan for select
> ename
> from scott.emp
> order by empno": There are not enough rules to produce a node with desired
> properties: convention=ENUMERABLE, sort=[1].
> Missing conversion is JdbcTableScan[sort: [] -> [0]]
> There is 1 empty subset: rel#34:Subset#0.JDBC.SCOTT.[0], the relevant part of
> the original plan is as follows
> 0:JdbcTableScan(table=[[SCOTT, EMP]])
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)