!6077 修复游标向量化codegen的core问题

Merge pull request !6077 from chenxiaobin/fixCodegen
This commit is contained in:
opengauss_bot
2024-08-20 09:25:14 +00:00
committed by Gitee
5 changed files with 179 additions and 3 deletions

View File

@ -608,6 +608,7 @@ void standard_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long co
} else {
CodeGenThreadRuntimeCodeGenerate();
}
estate->compileCodegen = true;
}
#endif
@ -843,8 +844,11 @@ void standard_ExecutorEnd(QueryDesc *queryDesc)
UnregisterSnapshot(estate->es_crosscheck_snapshot);
#ifdef ENABLE_LLVM_COMPILE
/* Do not release codegen in Fmgr and Procedure */
if (!t_thrd.codegen_cxt.g_runningInFmgr && u_sess->SPI_cxt._connected == -1) {
/*
* Do not release codegen in Fmgr and Procedure. And if codegen modulre
* is compiled, only estate which has compiled it can release.
*/
if (u_sess->SPI_cxt._connected == -1 && (CodeGenThreadObjectReady() || estate->compileCodegen)) {
CodeGenThreadTearDown();
}
#endif

View File

@ -207,6 +207,7 @@ EState* CreateExecutorState()
estate->cur_insert_autoinc = 0;
estate->next_autoinc = 0;
estate->es_is_flt_frame = (u_sess->attr.attr_common.enable_expr_fusion && u_sess->attr.attr_sql.query_dop_tmp == 1);
estate->compileCodegen = false;
/*
* Return the executor state structure
*/

View File

@ -739,6 +739,7 @@ typedef struct EState {
#ifdef USE_SPQ
List *es_sharenode;
#endif
bool compileCodegen;
} EState;
/*

View File

@ -539,6 +539,101 @@ select col_int, col_intervaltz from llvm_vecexpr_table_04 where nullif(col_inter
| ["Mon May 10 07:59:12 1937 PST" "Sat Jan 13 23:14:21 2001 PST"]
(15 rows)
CREATE TABLE t_rate_calculation (
id character varying(32) NOT NULL,
dispatch_no character varying(32) NOT NULL,
waybill_no character varying(32) NOT NULL,
adjustment_price numeric(18,4),
artifical_assessmen_price numeric(18,2),
manual_change numeric(18,2)
) WITH (orientation=row, compression=no);
CREATE TABLE t_vehicle_plan (
id character varying(32),
waybill_no character varying(20)
) WITH (orientation=row, compression=no);
CREATE TABLE t_plan_vehicle (
id character varying(32) NOT NULL,
plan_id character varying(32),
carrier_id character varying(32),
dispatch_no character varying(32)
) WITH (orientation=row, compression=no);
CREATE TABLE t_carrier_info (
id character varying(32) NOT NULL,
carrier_code character varying(20)
) WITH (orientation=row, compression=no);
CREATE TABLE t_waybill_info_local (
id character varying(32) NOT NULL,
waybill_no character varying(20)
) WITH (orientation=row, compression=no);
CREATE TABLE t_waybill_carrier (
id character varying(32) NOT NULL,
waybill_no character varying(20),
carrier_code character varying(20)
) WITH (orientation=row, compression=no);
insert into t_rate_calculation values (generate_series(1,10000),generate_series(1,10000),generate_series(1,10000),generate_series(1,10000),generate_series(1,10000),generate_series(1,10000));
insert into t_vehicle_plan values (generate_series(1,10000),generate_series(1,10000));
insert into t_plan_vehicle values (generate_series(1,10000),generate_series(1,10000),generate_series(1,10000),generate_series(1,10000));
insert into t_carrier_info values (generate_series(1,10000),generate_series(1,10000));
insert into t_waybill_info_local values (generate_series(1,10000),generate_series(1,10000));
insert into t_waybill_carrier values (generate_series(1,10000),generate_series(1,10000),generate_series(1,10000));
set try_vector_engine_strategy='force';
set codegen_cost_threshold = 100;
set enable_codegen = on;
explain (costs off) declare xc no scroll cursor for select rc.waybill_no 邮路代码, rc.dispatch_no 派车单, rc.adjustment_price+rc.artifical_assessmen_price +rc.manual_change 手工调账考核 from t_rate_calculation rc
left JOIN t_plan_vehicle pv on pv.dispatch_no=rc.dispatch_no
left join t_carrier_info ci on pv.carrier_id=ci.id--承运商
left join t_vehicle_plan vp on pv.plan_id=vp.id
left join t_waybill_info_local wl on vp.waybill_no=wl.waybill_no
left join t_waybill_carrier wc on ci.carrier_code=wc.carrier_code and wc.waybill_no=wl.waybill_no;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------
Row Adapter
-> Vector Hash Right Join
Hash Cond: ((pv.dispatch_no)::text = (rc.dispatch_no)::text)
-> Vector Hash Left Join
Hash Cond: (((ci.carrier_code)::text = (wc.carrier_code)::text) AND ((wl.waybill_no)::text = (wc.waybill_no)::text))
-> Vector Hash Right Join
Hash Cond: ((vp.id)::text = (pv.plan_id)::text)
-> Vector Hash Left Join
Hash Cond: ((vp.waybill_no)::text = (wl.waybill_no)::text)
-> Vector Adapter(type: BATCH MODE)
-> Seq Scan on t_vehicle_plan vp
-> Vector Adapter(type: BATCH MODE)
-> Seq Scan on t_waybill_info_local wl
-> Vector Hash Right Join
Hash Cond: ((ci.id)::text = (pv.carrier_id)::text)
-> Vector Adapter(type: BATCH MODE)
-> Seq Scan on t_carrier_info ci
-> Vector Adapter(type: BATCH MODE)
-> Seq Scan on t_plan_vehicle pv
-> Vector Adapter(type: BATCH MODE)
-> Seq Scan on t_waybill_carrier wc
-> Vector Adapter(type: BATCH MODE)
-> Seq Scan on t_rate_calculation rc
(23 rows)
begin;
declare xc no scroll cursor for select rc.waybill_no 邮路代码, rc.dispatch_no 派车单, rc.adjustment_price+rc.artifical_assessmen_price +rc.manual_change 手工调账考核 from t_rate_calculation rc
left JOIN t_plan_vehicle pv on pv.dispatch_no=rc.dispatch_no
left join t_carrier_info ci on pv.carrier_id=ci.id--承运商
left join t_vehicle_plan vp on pv.plan_id=vp.id
left join t_waybill_info_local wl on vp.waybill_no=wl.waybill_no
left join t_waybill_carrier wc on ci.carrier_code=wc.carrier_code and wc.waybill_no=wl.waybill_no;
move 1000 xc;
select 1;
?column?
----------
1
(1 row)
move 1000 xc;
end;
drop table t_rate_calculation;
drop table t_vehicle_plan;
drop table t_plan_vehicle;
drop table t_carrier_info;
drop table t_waybill_info_local;
drop table t_waybill_carrier;
----
--- clean table and resource
----

View File

@ -163,7 +163,82 @@ select col_int, col_real, col_decimal from llvm_vecexpr_table_04 where nullif(co
select col_int, col_intervaltz from llvm_vecexpr_table_04 where nullif(col_intervaltz, '["1937-06-11 23:59:12+08" "2001-11-14 15:14:21+08"]') is not NULL order by 1, 2;
CREATE TABLE t_rate_calculation (
id character varying(32) NOT NULL,
dispatch_no character varying(32) NOT NULL,
waybill_no character varying(32) NOT NULL,
adjustment_price numeric(18,4),
artifical_assessmen_price numeric(18,2),
manual_change numeric(18,2)
) WITH (orientation=row, compression=no);
CREATE TABLE t_vehicle_plan (
id character varying(32),
waybill_no character varying(20)
) WITH (orientation=row, compression=no);
CREATE TABLE t_plan_vehicle (
id character varying(32) NOT NULL,
plan_id character varying(32),
carrier_id character varying(32),
dispatch_no character varying(32)
) WITH (orientation=row, compression=no);
CREATE TABLE t_carrier_info (
id character varying(32) NOT NULL,
carrier_code character varying(20)
) WITH (orientation=row, compression=no);
CREATE TABLE t_waybill_info_local (
id character varying(32) NOT NULL,
waybill_no character varying(20)
) WITH (orientation=row, compression=no);
CREATE TABLE t_waybill_carrier (
id character varying(32) NOT NULL,
waybill_no character varying(20),
carrier_code character varying(20)
) WITH (orientation=row, compression=no);
insert into t_rate_calculation values (generate_series(1,10000),generate_series(1,10000),generate_series(1,10000),generate_series(1,10000),generate_series(1,10000),generate_series(1,10000));
insert into t_vehicle_plan values (generate_series(1,10000),generate_series(1,10000));
insert into t_plan_vehicle values (generate_series(1,10000),generate_series(1,10000),generate_series(1,10000),generate_series(1,10000));
insert into t_carrier_info values (generate_series(1,10000),generate_series(1,10000));
insert into t_waybill_info_local values (generate_series(1,10000),generate_series(1,10000));
insert into t_waybill_carrier values (generate_series(1,10000),generate_series(1,10000),generate_series(1,10000));
set try_vector_engine_strategy='force';
set codegen_cost_threshold = 100;
set enable_codegen = on;
explain (costs off) declare xc no scroll cursor for select rc.waybill_no , rc.dispatch_no , rc.adjustment_price+rc.artifical_assessmen_price +rc.manual_change from t_rate_calculation rc
left JOIN t_plan_vehicle pv on pv.dispatch_no=rc.dispatch_no
left join t_carrier_info ci on pv.carrier_id=ci.id--
left join t_vehicle_plan vp on pv.plan_id=vp.id
left join t_waybill_info_local wl on vp.waybill_no=wl.waybill_no
left join t_waybill_carrier wc on ci.carrier_code=wc.carrier_code and wc.waybill_no=wl.waybill_no;
begin;
declare xc no scroll cursor for select rc.waybill_no , rc.dispatch_no , rc.adjustment_price+rc.artifical_assessmen_price +rc.manual_change from t_rate_calculation rc
left JOIN t_plan_vehicle pv on pv.dispatch_no=rc.dispatch_no
left join t_carrier_info ci on pv.carrier_id=ci.id--
left join t_vehicle_plan vp on pv.plan_id=vp.id
left join t_waybill_info_local wl on vp.waybill_no=wl.waybill_no
left join t_waybill_carrier wc on ci.carrier_code=wc.carrier_code and wc.waybill_no=wl.waybill_no;
move 1000 xc;
select 1;
move 1000 xc;
end;
drop table t_rate_calculation;
drop table t_vehicle_plan;
drop table t_plan_vehicle;
drop table t_carrier_info;
drop table t_waybill_info_local;
drop table t_waybill_carrier;
----
--- clean table and resource
----
drop schema llvm_vecexpr_engine3 cascade ;
drop schema llvm_vecexpr_engine3 cascade ;