Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5371547

Browse files
committed
VOPS as FDW
1 parentdf44e1a commit5371547

File tree

4 files changed

+103
-139
lines changed

4 files changed

+103
-139
lines changed

‎Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# contrib/vops/Makefile
22

33
MODULE_big = vops
4-
OBJS = vops.o
4+
OBJS = vops.o vops_fdw.o deparse.o
55

66
EXTENSION = vops
77
DATA = vops--1.0.sql
88
PGFILEDESC = "vops - vectorized operations"
9-
CUSTOM_COPT = -O3
9+
CUSTOM_COPT = -O0
1010

1111
REGRESS = test
1212

‎tpch.sql‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,79 @@ order by
207207
l_linestatus;
208208
-- Seq time: 1490.143 ms
209209
-- Par time: 396.329 ms
210+
211+
212+
-- Access through FDW
213+
214+
create foreign table lineitem_fdw (
215+
l_shipdatedatenot null,
216+
l_quantity float4not null,
217+
l_extendedprice float4not null,
218+
l_discount float4not null,
219+
l_tax float4not null,
220+
l_returnflag"char"not null,
221+
l_linestatus"char"not null
222+
) server vops_server options (table_name'vops_lineitem');
223+
224+
select
225+
l_returnflag,
226+
l_linestatus,
227+
sum(l_quantity)as sum_qty,
228+
sum(l_extendedprice)as sum_base_price,
229+
sum(l_extendedprice*(1-l_discount))as sum_disc_price,
230+
sum(l_extendedprice*(1-l_discount)*(1+l_tax))as sum_charge,
231+
avg(l_quantity)as avg_qty,
232+
avg(l_extendedprice)as avg_price,
233+
avg(l_discount)as avg_disc,
234+
count(*)as count_order
235+
from
236+
lineitem_fdw
237+
where
238+
l_shipdate<='1998-12-01'
239+
group by
240+
l_returnflag,
241+
l_linestatus
242+
order by
243+
l_returnflag,
244+
l_linestatus;
245+
246+
select
247+
sum(l_extendedprice*l_discount)as revenue
248+
from
249+
lineitem_fdw
250+
where
251+
l_shipdate between'1996-01-01'and'1997-01-01'
252+
and l_discount between0.08and0.1
253+
and l_quantity<24;
254+
255+
create foreign table lineitem_projection_fdw (
256+
l_shipdatedatenot null,
257+
l_quantity float4not null,
258+
l_extendedprice float4not null,
259+
l_discount float4not null,
260+
l_tax float4not null,
261+
l_returnflag"char"not null,
262+
l_linestatus"char"not null
263+
) server vops_server options (table_name'vops_lineitem_projection');
264+
265+
select
266+
l_returnflag,
267+
l_linestatus,
268+
sum(l_quantity)as sum_qty,
269+
sum(l_extendedprice)as sum_base_price,
270+
sum(l_extendedprice*(1-l_discount))as sum_disc_price,
271+
sum(l_extendedprice*(1-l_discount)*(1+l_tax))as sum_charge,
272+
avg(l_quantity)as avg_qty,
273+
avg(l_extendedprice)as avg_price,
274+
avg(l_discount)as avg_disc,
275+
count(*)as count_order
276+
from
277+
lineitem_projection_fdw
278+
where
279+
l_shipdate<='1998-12-01'
280+
group by
281+
l_returnflag,
282+
l_linestatus
283+
order by
284+
l_returnflag,
285+
l_linestatus;

‎vops--1.0.sql‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,3 +2651,19 @@ create cast (vops_bool as bool) with function filter(vops_bool) AS IMPLICIT;
26512651
createfunctionis_null(anyelement) returns vops_boolas'MODULE_PATHNAME','vops_is_null' language C parallel safe immutable;
26522652
createfunctionis_not_null(anyelement) returns vops_boolas'MODULE_PATHNAME','vops_is_not_null' language C parallel safe immutable;
26532653

2654+
CREATEFUNCTIONvops_fdw_handler()
2655+
RETURNS fdw_handler
2656+
AS'MODULE_PATHNAME'
2657+
LANGUAGE C STRICT;
2658+
2659+
CREATEFUNCTIONvops_fdw_validator(text[],oid)
2660+
RETURNS void
2661+
AS'MODULE_PATHNAME'
2662+
LANGUAGE C STRICT;
2663+
2664+
CREATE FOREIGN DATA WRAPPER vops_fdw
2665+
HANDLER vops_fdw_handler
2666+
VALIDATOR vops_fdw_validator;
2667+
2668+
CREATE SERVER vops_server FOREIGN DATA WRAPPER vops_fdw;
2669+

‎vops.c‎

Lines changed: 9 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include"nodes/nodeFuncs.h"
4444
#include"nodes/makefuncs.h"
4545
#include"nodes/pg_list.h"
46+
#include"vops.h"
4647

4748
#ifdefPG_MODULE_MAGIC
4849
PG_MODULE_MAGIC;
@@ -52,142 +53,7 @@ PG_MODULE_MAGIC;
5253
void_PG_init(void);
5354
void_PG_fini(void);
5455

55-
typedefenum
56-
{
57-
VOPS_BOOL,
58-
VOPS_CHAR,
59-
VOPS_INT2,
60-
VOPS_INT4,
61-
VOPS_INT8,
62-
VOPS_DATE,
63-
VOPS_TIMESTAMP,
64-
VOPS_FLOAT4,
65-
VOPS_FLOAT8,
66-
VOPS_LAST,
67-
}vops_type;
68-
69-
typedefenum
70-
{
71-
VOPS_AGG_SUM,
72-
VOPS_AGG_AVG,
73-
VOPS_AGG_MAX,
74-
VOPS_AGG_MIN,
75-
VOPS_AGG_COUNT,
76-
VOPS_AGG_LAST
77-
}vops_agg_kind;
78-
79-
80-
#defineTILE_SIZE 64/* just because of maximum size of bitmask */
81-
#defineMAX_SQL_STMT_LEN 1024
82-
#defineMAX_CSV_LINE_LEN 4096
83-
#defineMAX_TILE_STRLEN (TILE_SIZE*16)
84-
#defineINIT_MAP_SIZE (1024*1024)
85-
86-
staticuint64filter_mask;
87-
typedeflong longlong64;
88-
89-
/* Common prefix for all tile */
90-
typedefstruct {
91-
uint64null_mask;
92-
uint64empty_mask;
93-
}vops_tile_hdr;
94-
95-
#defineTILE(TYPE,CTYPE)\
96-
typedef struct {\
97-
vops_tile_hdr hdr;\
98-
CTYPE payload[TILE_SIZE];\
99-
} vops_##TYPE
100-
101-
TILE(char,char);
102-
TILE(int2,int16);
103-
TILE(int4,int32);
104-
TILE(int8,int64);
105-
TILE(float4,float4);
106-
TILE(float8,float8);
107-
108-
typedefstruct {
109-
vops_tile_hdrhdr;
110-
uint64payload;
111-
}vops_bool;
112-
113-
typedefstruct {
114-
uint64count;
115-
doublesum;
116-
}vops_avg_state;
117-
118-
typedefstruct {
119-
uint64count;
120-
doublesum;
121-
doublesum2;
122-
}vops_var_state;
123-
124-
typedefstruct {
125-
HTAB*htab;
126-
intn_aggs;
127-
vops_typeagg_type;
128-
vops_agg_kind*agg_kinds;
129-
}vops_agg_state;
130-
131-
typedefunion {
132-
boolb;
133-
charch;
134-
int16i2;
135-
int32i4;
136-
int64i8;
137-
floatf4;
138-
doublef8;
139-
}vops_value;
140-
141-
typedefstruct {
142-
vops_valueacc;
143-
uint64count;
144-
}vops_agg_value;
145-
146-
typedefstruct {
147-
int64group_by;
148-
uint64count;
149-
vops_agg_valuevalues[1];
150-
}vops_group_by_entry;
151-
152-
#defineVOPS_AGGREGATES_ATTRIBUTES 3
153-
154-
typedefstruct {
155-
HASH_SEQ_STATUSiter;
156-
TupleDescdesc;
157-
Datum*elems;
158-
bool*nulls;
159-
int16elmlen;
160-
boolelmbyval;
161-
charelmalign;
162-
}vops_reduce_context;
163-
164-
typedefstruct {
165-
Datum*values;
166-
bool*nulls;
167-
vops_type*types;
168-
TupleDescdesc;
169-
intn_attrs;
170-
inttile_pos;
171-
uint64filter_mask;
172-
vops_tile_hdr**tiles;
173-
}vops_unnest_context;
174-
175-
typedefstruct {
176-
vops_float8tile;
177-
doublesum;
178-
doublesum2;
179-
uint64count;
180-
}vops_window_state;
181-
182-
183-
typedefstruct {
184-
vops_typetid;
185-
int16len;
186-
boolbyval;
187-
charalign;
188-
FmgrInfoinproc;
189-
Oidinproc_param_oid;
190-
}vops_type_info;
56+
uint64filter_mask;
19157

19258
staticstruct {
19359
charconst*name;
@@ -233,7 +99,7 @@ static vops_agg_state* vops_init_agg_state(char const* aggregates, Oid elem_type
23399
staticvops_agg_state*vops_create_agg_state(intn_aggregates);
234100
staticvoidvops_agg_state_accumulate(vops_agg_state*state,int64group_by,inti,Datum*tiles,bool*nulls);
235101

236-
staticvops_typevops_get_type(Oidtypid)
102+
vops_typevops_get_type(Oidtypid)
237103
{
238104
inti;
239105
if (vops_type_map[0].oid==InvalidOid) {
@@ -1587,6 +1453,12 @@ Datum vops_populate(PG_FUNCTION_ARGS)
15871453
HeapTuplespi_tuple=SPI_tuptable->vals[0];
15881454
spi_tupdesc=SPI_tuptable->tupdesc;
15891455
if (j==TILE_SIZE) {
1456+
for (i=0;i<n_attrs;i++) {
1457+
if (types[i].tid!=VOPS_LAST) {
1458+
vops_tile_hdr*tile= (vops_tile_hdr*)DatumGetPointer(values[i]);
1459+
tile->empty_mask=0;
1460+
}
1461+
}
15901462
insert_tuple(values,nulls);
15911463
j=0;
15921464
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp