fix record type issue caused by composite datum
This commit is contained in:
@ -720,7 +720,6 @@ static Datum ExecEvalWholeRowVar(
|
||||
{
|
||||
Var* variable = (Var*)wrvstate->xprstate.expr;
|
||||
TupleTableSlot* slot = NULL;
|
||||
TupleDesc slot_tupdesc;
|
||||
bool needslow = false;
|
||||
|
||||
if (isDone != NULL)
|
||||
@ -802,21 +801,13 @@ static Datum ExecEvalWholeRowVar(
|
||||
if (wrvstate->wrv_junkFilter != NULL)
|
||||
slot = ExecFilterJunk(wrvstate->wrv_junkFilter, slot);
|
||||
|
||||
slot_tupdesc = slot->tts_tupleDescriptor;
|
||||
|
||||
/*
|
||||
* If it's a RECORD Var, we'll use the slot's type ID info. It's likely
|
||||
* that the slot's type is also RECORD; if so, make sure it's been
|
||||
* "blessed", so that the Datum can be interpreted later.
|
||||
*
|
||||
* If the Var identifies a named composite type, we must check that the
|
||||
* actual tuple type is compatible with it.
|
||||
*/
|
||||
if (variable->vartype == RECORDOID) {
|
||||
if (slot_tupdesc->tdtypeid == RECORDOID && slot_tupdesc->tdtypmod < 0)
|
||||
assign_record_type_typmod(slot_tupdesc);
|
||||
} else {
|
||||
if (variable->vartype != RECORDOID) {
|
||||
TupleDesc var_tupdesc;
|
||||
TupleDesc slot_tupdesc;
|
||||
int i;
|
||||
|
||||
/*
|
||||
@ -833,6 +824,8 @@ static Datum ExecEvalWholeRowVar(
|
||||
*/
|
||||
var_tupdesc = lookup_rowtype_tupdesc(variable->vartype, -1);
|
||||
|
||||
slot_tupdesc = slot->tts_tupleDescriptor;
|
||||
|
||||
if (var_tupdesc->natts != slot_tupdesc->natts)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
@ -886,6 +879,7 @@ static Datum ExecEvalWholeRowFast(
|
||||
{
|
||||
Var* variable = (Var*)wrvstate->xprstate.expr;
|
||||
TupleTableSlot* slot = NULL;
|
||||
TupleDesc slot_tupdesc;
|
||||
HeapTuple tuple;
|
||||
TupleDesc tupleDesc;
|
||||
HeapTupleHeader dtuple;
|
||||
@ -915,6 +909,17 @@ static Datum ExecEvalWholeRowFast(
|
||||
if (wrvstate->wrv_junkFilter != NULL)
|
||||
slot = ExecFilterJunk(wrvstate->wrv_junkFilter, slot);
|
||||
|
||||
/*
|
||||
* If it's a RECORD Var, we'll use the slot's type ID info. It's likely
|
||||
* that the slot's type is also RECORD; if so, make sure it's been
|
||||
* "blessed", so that the Datum can be interpreted later.
|
||||
*/
|
||||
slot_tupdesc = slot->tts_tupleDescriptor;
|
||||
if (variable->vartype == RECORDOID) {
|
||||
if (slot_tupdesc->tdtypeid == RECORDOID && slot_tupdesc->tdtypmod < 0)
|
||||
assign_record_type_typmod(slot_tupdesc);
|
||||
}
|
||||
|
||||
tuple = ExecFetchSlotTuple(slot);
|
||||
tupleDesc = slot->tts_tupleDescriptor;
|
||||
|
||||
|
||||
37
src/test/regress/expected/composite_datum_record.out
Normal file
37
src/test/regress/expected/composite_datum_record.out
Normal file
@ -0,0 +1,37 @@
|
||||
--
|
||||
-- check for over-optimization of whole-row Var referencing an Append plan
|
||||
--
|
||||
create table int4_test(f1 int4);
|
||||
select (select q from (select 1,2,3 where f1>0 union all select 4,5,6 where f1<=0) q) from int4_test;
|
||||
q
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
select (select q from (select 1,2,3 where f1>0 union all select 4,5,6.0 where f1<=0) q) from int4_test;
|
||||
q
|
||||
---
|
||||
(0 rows)
|
||||
|
||||
insert into int4_test(f1) values(' 0 ');
|
||||
insert into int4_test(f1) values('123456 ');
|
||||
select * from int4_test;
|
||||
f1
|
||||
--------
|
||||
0
|
||||
123456
|
||||
(2 rows)
|
||||
|
||||
select (select q from (select 1,2,3 where f1>0 union all select 4,5,6 where f1<=0) q) from int4_test;
|
||||
q
|
||||
---------
|
||||
(4,5,6)
|
||||
(1,2,3)
|
||||
(2 rows)
|
||||
|
||||
select (select q from (select 1,2,3 where f1>0 union all select 4,5,6.0 where f1<=0) q) from int4_test;
|
||||
q
|
||||
-----------
|
||||
(4,5,6.0)
|
||||
(1,2,3)
|
||||
(2 rows)
|
||||
|
||||
@ -916,3 +916,4 @@ test: fdw_audit
|
||||
test: gs_global_config_audit
|
||||
test: detail
|
||||
test: gs_dump_encrypt
|
||||
test: composite_datum_record
|
||||
|
||||
11
src/test/regress/sql/composite_datum_record.sql
Normal file
11
src/test/regress/sql/composite_datum_record.sql
Normal file
@ -0,0 +1,11 @@
|
||||
--
|
||||
-- check for over-optimization of whole-row Var referencing an Append plan
|
||||
--
|
||||
create table int4_test(f1 int4);
|
||||
select (select q from (select 1,2,3 where f1>0 union all select 4,5,6 where f1<=0) q) from int4_test;
|
||||
select (select q from (select 1,2,3 where f1>0 union all select 4,5,6.0 where f1<=0) q) from int4_test;
|
||||
insert into int4_test(f1) values(' 0 ');
|
||||
insert into int4_test(f1) values('123456 ');
|
||||
select * from int4_test;
|
||||
select (select q from (select 1,2,3 where f1>0 union all select 4,5,6 where f1<=0) q) from int4_test;
|
||||
select (select q from (select 1,2,3 where f1>0 union all select 4,5,6.0 where f1<=0) q) from int4_test;
|
||||
Reference in New Issue
Block a user