cloudberry
cloudberry copied to clipboard
[Bug] The plan generated by ORCA misses `resorigtbl` in TargetEntry when filter is false
Apache Cloudberry version
cloudberry: Latest jdbc--42.7.5
What happened
import java.sql.*;
public class JdbcTest {
public static void main(String[] args) {
/* create table tab_jdbc_metadata (a numeric(38,4) not null, b int not null); */
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/gpadmin", "gpadmin", "gpadmin")) {
System.out.println("Connected to PostgreSQL database!");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM tab_jdbc_metadata WHERE 1=0");
ResultSetMetaData metaData = resultSet.getMetaData();
int ncolumns = metaData.getColumnCount();
for (int i = 1; i <= ncolumns; i++) {
System.out.println("Column name: " + metaData.getColumnName(i) +
", Precision: " +metaData.getPrecision(i) +
", Scale: " + metaData.getScale(i) +
", Nullable: " + metaData.isNullable(i));
}
} catch (Exception e) {
System.out.println("Connection failure.");
e.printStackTrace();
}
}
}
expected result is :
Column name: a, Precision: 38, Scale: 4, Nullable: 0
Column name: b, Precision: 10, Scale: 0, Nullable: 0
but result is in cloudberry is :
Column name: a, Precision: 38, Scale: 4, Nullable: 2
Column name: b, Precision: 10, Scale: 0, Nullable: 2
### What you think should happen instead
_No response_
### How to reproduce
see above
### Operating System
centos7/macos
### Anything else
_No response_
### Are you willing to submit PR?
- [ ] Yes, I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/cloudberry/blob/main/CODE_OF_CONDUCT.md).
Have dived into this bug, the below is my found:
- when using postgres planner, the error wouldn't happen. It's the orca's bug.
- Only when the filter is false, it fails. The plan generated by orca is as below:
(char *) 0x0000000158008850 "{RESULT :startup_cost 0.00 :total_cost 0.00 :plan_rows 0 :plan_width 12 :parallel_aware false :parallel_safe false :plan_node_id 0 :targetlist ({TARGETENTRY :expr {VAR :varno 65001 :varattno 1 :vartype 1700 :vartypmod 2490376 :varcollid 0 :varlevelsup 0 :varnoold 65001 :varoattno 1 :location -1} :resno 1 :resname a :ressortgroupref 0 :resorigtbl 0 :resorigcol 0 :resjunk false} {TARGETENTRY :expr {VAR :varno 65001 :varattno 2 :vartype 23 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 65001 :varoattno 2 :location -1} :resno 2 :resname b :ressortgroupref 0 :resorigtbl 0 :resorigcol 0 :resjunk false}) :qual <> :lefttree {RESULT :startup_cost 0.00 :total_cost 0.00 :plan_rows 0 :plan_width 12 :parallel_aware false :parallel_safe false :plan_node_id 1 :targetlist ({TARGETENTRY :expr {CONST :consttype 1700 :consttypmod -1 :constcollid 0 :constlen -1 :constbyval false :constisnull true :location 0 :constvalue <>} :resno 1 :resname a :ressortgroupref 0 :resorigtbl 0 :resorigcol 0 :resjunk false} {TARGETENTRY :expr {CONST :consttype 23 :consttypmod -1 :constcollid 0 :constlen 4 :constbyval true :constisnull true :location 0 :constvalue <>} :resno 2 :resname b :ressortgroupref 0 :resorigtbl 0 :resorigcol 0 :resjunk false} {TARGETENTRY :expr {CONST :consttype 27 :consttypmod -1 :constcollid 0 :constlen 6 :constbyval false :constisnull true :location 0 :constvalue <>} :resno 3 :resname ctid :ressortgroupref 0 :resorigtbl 0 :resorigcol 0 :resjunk false} {TARGETENTRY :expr {CONST :consttype 28 :consttypmod -1 :constcollid 0 :constlen 4 :constbyval true :constisnull true :location 0 :constvalue <>} :resno 4 :resname xmin :ressortgroupref 0 :resorigtbl 0 :resorigcol 0 :resjunk false} {TARGETENTRY :expr {CONST :consttype 29 :consttypmod -1 :constcollid 0 :constlen 4 :constbyval true :constisnull true :location 0 :constvalue <>} :resno 5 :resname cmin :ressortgroupref 0 :resorigtbl 0 :resorigcol 0 :resjunk false} {TARGETENTRY :expr {CONST :consttype 28 :consttypmod -1 :constcollid 0 :constlen 4 :constbyval true :constisnull true :location 0 :constvalue <>} :resno 6 :resname xmax :ressortgroupref 0 :resorigtbl 0 :resorigcol 0 :resjunk false} {TARGETENTRY :expr {CONST :consttype 29 :consttypmod -1 :constcollid 0 :constlen 4 :constbyval true :constisnull true :location 0 :constvalue <>} :resno 7 :resname cmax :ressortgroupref 0 :resorigtbl 0 :resorigcol 0 :resjunk false} {TARGETENTRY :expr {CONST :consttype 26 :consttypmod -1 :constcollid 0 :constlen 4 :constbyval true :constisnull true :location 0 :constvalue <>} :resno 8 :resname tableoid :ressortgroupref 0 :resorigtbl 0 :resorigcol 0 :resjunk false} {TARGETENTRY :expr {CONST :consttype 23 :consttypmod -1 :constcollid 0 :constlen 4 :constbyval true :constisnull true :location 0 :constvalue <>} :resno 9 :resname gp_segment_id :ressortgroupref 0 :resorigtbl 0 :resorigcol 0 :resjunk false}) :qual <> :lefttree <> :righttree <> :initPlan <> :extParam (b) :allParam (b) :flow <> :operatorMemKB 0 :resconstantqual ({CONST :consttype 16 :consttypmod -1 :constcollid 0 :constlen 1 :constbyval true :constisnull false :location 0 :constvalue 1 [ 0 0 0 0 0 0 0 0 ]}) :numHashFilterCols 0 :hashFilterColIdx :hashFilterFuncs } :righttree <> :initPlan <> :extParam (b) :allParam (b) :flow <> :operatorMemKB 0 :resconstantqual <> :numHashFilterCols 0 :hashFilterColIdx :hashFilterFuncs }"
In the function CTranslatorExprToDXL::PdxlnResultFromConstTableGet, orca translates the plan into dxl. We can see that the resorigtbl lost in the above plan as PdxlnResultFromConstTableGet doesn't contain TableDescription info.