Skip to content

Commit ff8e5c5

Browse files
committed
[PGPRO-6448] Function unnest renamed to vops_unnest
1 parent 24d08e8 commit ff8e5c5

File tree

7 files changed

+39
-39
lines changed

7 files changed

+39
-39
lines changed

Diff for: README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ There are also two important restrictions:
415415
Example of using window functions with
416416
VOPS:
417417

418-
select unnest(t.*) from (select mcount(*) over w,mcount(x) over w,msum(x) over w,mavg(x) over w,mmin(x) over w,mmax(x) over w,x - lag(x) over w
418+
select vops_unnest(t.*) from (select mcount(*) over w,mcount(x) over w,msum(x) over w,mavg(x) over w,mmin(x) over w,mmax(x) over w,x - lag(x) over w
419419
from v window w as (rows between unbounded preceding and current row)) t;
420420

421421
### <span id="indexes">Using indexes</span>
@@ -571,16 +571,16 @@ It accepts name of target VOPS table, path to CSV file, optional
571571
separator (default is ',') and number of lines in CSV header (no header
572572
by default). The function returns number of imported rows.
573573

574-
### <span id="unnest">Back to normal tuples</span>
574+
### <span id="vops_unnest">Back to normal tuples</span>
575575

576576
A query from VOPS projection returns set of tiles. Output function of
577577
tile type is able to print content of the tile. But in some cases it is
578578
preferable to transfer result to normal (horizontal) format where each
579-
tuple represents one record. It can be done using `unnest`
579+
tuple represents one record. It can be done using `vops_unnest`
580580
function:
581581

582-
postgres=# select unnest(l.*) from vops_lineitem l where filter(l_shipdate <= '1998-12-01'::date) limit 3;
583-
unnest
582+
postgres=# select vops_unnest(l.*) from vops_lineitem l where filter(l_shipdate <= '1998-12-01'::date) limit 3;
583+
vops_unnest
584584
---------------------------------------
585585
(1996-03-13,17,33078.9,0.04,0.02,N,O)
586586
(1996-04-12,36,38306.2,0.09,0.06,N,O)
@@ -589,18 +589,18 @@ tuple represents one record. It can be done using `unnest`
589589

590590
### <span id="fdw">Back to normal tables</span>
591591

592-
As it was mentioned in previous section, `unnest` function can scatter
593-
records with VOPS types into normal records with scalar types. So it is
594-
possible to use this records in arbitrary SQL queries. But there are two
595-
problems with unnest function:
592+
As it was mentioned in previous section, `vops_unnest` function can
593+
scatter records with VOPS types into normal records with scalar types.
594+
So it is possible to use this records in arbitrary SQL queries. But
595+
there are two problems with vops_unnest function:
596596

597597
1. It is not convenient to use. This function has no static knowledge
598598
about the format of output record and this is why programmer has to
599599
specify it manually, if here wants to decompose this record.
600600
2. PostgreSQL optimizer has completely no knowledge on result of
601-
transformation performed by unnest() function. This is why it is not
602-
able to choose optimal query execution plan for data retrieved from
603-
VOPS table.
601+
transformation performed by vops_unnest() function. This is why it
602+
is not able to choose optimal query execution plan for data
603+
retrieved from VOPS table.
604604

605605
Fortunately Postgres provides solution for both of this problem: foreign
606606
data wrappers (FDW). In our case data is not really "foreign": it is

Diff for: expected/test.out

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ select populate(destination:='v'::regclass, source:='s'::regclass);
99
6
1010
(1 row)
1111

12-
select unnest(v.*) from v where x > 1;
13-
unnest
14-
--------
12+
select vops_unnest(v.*) from v where x > 1;
13+
vops_unnest
14+
-------------
1515
(2)
1616
(3)
1717
(4)
@@ -71,8 +71,8 @@ select count(*) from v where coalesce(x, 0.0::float8::vops_float4) >= 0;
7171
6
7272
(1 row)
7373

74-
select unnest(t.*) from (select mcount(*) over w,mcount(x) over w,msum(x) over w,mavg(x) over w,mmin(x) over w,mmax(x) over w,x - lag(x) over w from v window w as (rows between unbounded preceding and current row)) t;
75-
unnest
74+
select vops_unnest(t.*) from (select mcount(*) over w,mcount(x) over w,msum(x) over w,mavg(x) over w,mmin(x) over w,mmax(x) over w,x - lag(x) over w from v window w as (rows between unbounded preceding and current row)) t;
75+
vops_unnest
7676
-------------------
7777
(1,1,1,1,1,1,)
7878
(2,2,3,1.5,1,2,1)
@@ -92,9 +92,9 @@ select populate(destination:='v2'::regclass, source:='s2'::regclass,sort:='id');
9292
100
9393
(1 row)
9494

95-
select unnest(t.*) from (select msum(x,10) over (order by first(id)) from v2) t;
96-
unnest
97-
--------
95+
select vops_unnest(t.*) from (select msum(x,10) over (order by first(id)) from v2) t;
96+
vops_unnest
97+
-------------
9898
(1)
9999
(3)
100100
(6)

Diff for: sql/test.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ create table s(x real);
44
create table v(x vops_float4);
55
insert into s values(1.0),(2.0),(null),(3.0),(null),(4.0);
66
select populate(destination:='v'::regclass, source:='s'::regclass);
7-
select unnest(v.*) from v where x > 1;
7+
select vops_unnest(v.*) from v where x > 1;
88
select countall(*) from v where x is not null;
99
select count(*) from v where x is null;
1010
select count(*) from v where x is not null;
@@ -14,14 +14,14 @@ select count(*),count(x),sum(x),avg(x),min(x),max(x),variance(x),var_pop(x),var_
1414
select count(*),count(x),sum(x),avg(x),min(x),max(x),variance(x),var_pop(x),var_samp(x),stddev(x),stddev_pop(x),stddev_samp(x) from s where x > 1.0;
1515
select count(*) from v where ifnull(x, 0) >= 0;
1616
select count(*) from v where coalesce(x, 0.0::float8::vops_float4) >= 0;
17-
select unnest(t.*) from (select mcount(*) over w,mcount(x) over w,msum(x) over w,mavg(x) over w,mmin(x) over w,mmax(x) over w,x - lag(x) over w from v window w as (rows between unbounded preceding and current row)) t;
17+
select vops_unnest(t.*) from (select mcount(*) over w,mcount(x) over w,msum(x) over w,mavg(x) over w,mmin(x) over w,mmax(x) over w,x - lag(x) over w from v window w as (rows between unbounded preceding and current row)) t;
1818

1919
create table s2(x float8, id serial);
2020
insert into s2(select generate_series(1,100));
2121
create table v2(x vops_float8, id vops_int4);
2222
select populate(destination:='v2'::regclass, source:='s2'::regclass,sort:='id');
2323

24-
select unnest(t.*) from (select msum(x,10) over (order by first(id)) from v2) t;
24+
select vops_unnest(t.*) from (select msum(x,10) over (order by first(id)) from v2) t;
2525
select sum(x) over (order by id rows between 9 preceding and current row) from s2;
2626

2727
set vops.auto_substitute_projections=on;

Diff for: tpch2.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ select
118118
count(*),
119119
sum(l_extendedprice * (1-l_discount)) as revenue
120120
from
121-
(select c.* from vcustomer vc, unnest(vc.*) c(c_custkey int4,c_nationkey int4,c_acctbal real)) c1
121+
(select c.* from vcustomer vc, vops_unnest(vc.*) c(c_custkey int4,c_nationkey int4,c_acctbal real)) c1
122122
join
123-
(select o.* from vorders vo,unnest(vo.*) o(o_orderkey int4,o_custkey int4,o_orderstatus "char",
123+
(select o.* from vorders vo,vops_unnest(vo.*) o(o_orderkey int4,o_custkey int4,o_orderstatus "char",
124124
o_totalprice real,o_orderdate date,o_shippriority int4)
125125
where vo.o_orderdate >= '1996-01-01'::date and vo.o_orderdate < '1997-01-01'::date) o1
126126
on c_custkey = o_custkey
127127
join
128-
(select l.* from vlineitem vl, unnest(vl.*) l(l_suppkey int4,l_orderkey int4,l_partkey int4,l_shipdate date,l_quantity float4,
128+
(select l.* from vlineitem vl, vops_unnest(vl.*) l(l_suppkey int4,l_orderkey int4,l_partkey int4,l_shipdate date,l_quantity float4,
129129
l_extendedprice float4,l_discount float4,l_tax float4,l_returnflag "char",l_linestatus "char")) l1 on l_orderkey = o_orderkey
130130
join
131-
(select s.* from vsupplier vs,unnest(vs.*) s(s_suppkey int4,s_nationkey int4,s_acctbal real)) s1 on l_suppkey = s_suppkey
131+
(select s.* from vsupplier vs,vops_unnest(vs.*) s(s_suppkey int4,s_nationkey int4,s_acctbal real)) s1 on l_suppkey = s_suppkey
132132
join nation on c_nationkey = n_nationkey
133133
join region on n_regionkey = r_regionkey
134134
where

Diff for: vops--1.0.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* contrib/vops/vops.sql */
1+
/* contrib/vops/vops--1.0.sql */
22

33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "create extension vops" to load this file. \quit
@@ -3453,7 +3453,7 @@ create function import(destination regclass, csv_path cstring, separator cstring
34533453
create type vops_aggregates as(group_by int8, count int8, aggs float8[]);
34543454
create function reduce(bigint) returns setof vops_aggregates as 'MODULE_PATHNAME','vops_reduce' language C parallel safe strict immutable;
34553455

3456-
create function unnest(anyelement) returns setof record as 'MODULE_PATHNAME','vops_unnest' language C parallel safe strict immutable;
3456+
create function vops_unnest(anyelement) returns setof record as 'MODULE_PATHNAME','vops_unnest' language C parallel safe strict immutable;
34573457

34583458
create cast (vops_bool as bool) with function filter(vops_bool) AS IMPLICIT;
34593459

Diff for: vops.html

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h1>Vectorized Operations (VOPS)</h1>
1515
<li><a href="#window">Vector window functions</a></li>
1616
<li><a href="#indexes">Using indexes</a></li>
1717
<li><a href="#populating">Preparing data for VOPS</a></li>
18-
<li><a href="#unnest">Back to normal tuples</a></li>
18+
<li><a href="#vops_unnest">Back to normal tuples</a></li>
1919
<li><a href="#fdw">Back to normal tables</a></li>
2020
</ul>
2121
<li><a href="#transform">Standard SQL query transformation</a></li>
@@ -389,7 +389,7 @@ <h3><a name="window">Vector window functions</a></h3>
389389
Example of using window functions with VOPS:
390390
</p>
391391
<pre>
392-
select unnest(t.*) from (select mcount(*) over w,mcount(x) over w,msum(x) over w,mavg(x) over w,mmin(x) over w,mmax(x) over w,x - lag(x) over w
392+
select vops_unnest(t.*) from (select mcount(*) over w,mcount(x) over w,msum(x) over w,mavg(x) over w,mmin(x) over w,mmax(x) over w,x - lag(x) over w
393393
from v window w as (rows between unbounded preceding and current row)) t;
394394
</pre>
395395

@@ -562,15 +562,15 @@ <h3><a name="populating">Preparing data for VOPS</a></h3>
562562
(no header by default). The function returns number of imported rows.
563563
</p>
564564

565-
<h3><a name="unnest">Back to normal tuples</a></h3>
565+
<h3><a name="vops_unnest">Back to normal tuples</a></h3>
566566
<p>
567567
A query from VOPS projection returns set of tiles. Output function of tile type is able to print content of the tile.
568568
But in some cases it is preferable to transfer result to normal (horizontal) format where each tuple represents one record.
569-
It can be done using <code>unnest</code> function:
569+
It can be done using <code>vops_unnest</code> function:
570570
</p>
571571
<pre>
572-
postgres=# select unnest(l.*) from vops_lineitem l where filter(l_shipdate &lt;= '1998-12-01'::date) limit 3;
573-
unnest
572+
postgres=# select vops_unnest(l.*) from vops_lineitem l where filter(l_shipdate &lt;= '1998-12-01'::date) limit 3;
573+
vops_unnest
574574
---------------------------------------
575575
(1996-03-13,17,33078.9,0.04,0.02,N,O)
576576
(1996-04-12,36,38306.2,0.09,0.06,N,O)
@@ -581,14 +581,14 @@ <h3><a name="unnest">Back to normal tuples</a></h3>
581581

582582
<h3><a name="fdw">Back to normal tables</a></h3>
583583
<p>
584-
As it was mentioned in previous section, <code>unnest</code> function can scatter records with VOPS types into normal records with scalar types.
584+
As it was mentioned in previous section, <code>vops_unnest</code> function can scatter records with VOPS types into normal records with scalar types.
585585
So it is possible to use this records in arbitrary SQL queries.
586-
But there are two problems with unnest function:
586+
But there are two problems with vops_unnest function:
587587
</p>
588588
<ol>
589589
<li>It is not convenient to use. This function has no static knowledge about the format of output record and this is why programmer has to specify it manually,
590590
if here wants to decompose this record.</li>
591-
<li>PostgreSQL optimizer has completely no knowledge on result of transformation performed by unnest() function.
591+
<li>PostgreSQL optimizer has completely no knowledge on result of transformation performed by vops_unnest() function.
592592
This is why it is not able to choose optimal query execution plan for data retrieved from VOPS table.</li>
593593
</ol>
594594
<p>

Diff for: vops_fdw.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
15091509
}
15101510
appendStringInfoString(&sql, " FROM ");
15111511
vopsDeparseRelation(&sql, relation);
1512-
appendStringInfo(&sql, " t,unnest(t) r(%s)", record.data);
1512+
appendStringInfo(&sql, " t,vops_unnest(t) r(%s)", record.data);
15131513

15141514
portal = SPI_cursor_open_with_args(NULL, sql.data, 0, NULL, NULL, NULL, true, 0);
15151515

0 commit comments

Comments
 (0)