You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -571,6 +572,122 @@ <h3><a name="unnest">Back to normal tuples</a></h3>
571
572
</pre>
572
573
573
574
575
+
<h3><aname="fdw">Back to normal tables</a></h3>
576
+
<p>
577
+
As it was mentioned in previous section, <code>unnest</code> function can scatter records with VOPS types into normal records with scalar types.
578
+
So it is possible to use this records in arbitrary SQL queries.
579
+
But there are two problems with unnest function:
580
+
</p>
581
+
<ol>
582
+
<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,
583
+
if here wants to decompose this record.</li>
584
+
<li>PostgreSQL optimizer has completely no knowledge on result of transformation performed by unnest() function.
585
+
This is why it is not able to choose optimal query execution plan for data retrieved from VOPS table.</li>
586
+
</ol>
587
+
<p>
588
+
Fortunately Postgres provides solution for both of this problem: foreign data wrappers (FDW). In our case data is not really "foreign": it is stored inside our own database.
589
+
But in alternatives (VOPS) format. VOPS FDW allows to "hide" specific of VOPS format and run normal SQL queries on VOPS tables.
590
+
FDW allows the following:
591
+
</p>
592
+
<ol>
593
+
<li>Extract data from VOPS table in normal (horizontal) format so that it can be proceeded by upper nodes in query execution plan.</li>
594
+
<li>Pushdown to VOPS operations that can be efficiently executed using vectorized operations on VOPS types: filtering and aggregation.</li>
595
+
<li>Provide statistic for underlying table which can be used by query optimizer.</li>
596
+
</ol>
597
+
598
+
<p>
599
+
So, by placing VOPS projection under FDW, we can efficiently perform sequential scan and aggregation queries as if them will be explicitly written for VOPS table
600
+
and at the same time be able to execute any other queries on this data, including joins, CTEs,...
601
+
Query can be written in standard SQL without usage of any VOPS specific functions.
602
+
</p>
603
+
604
+
<p>
605
+
Below is an example of creating VOPS FDW and running some queries on it:
606
+
</p>
607
+
608
+
<pre>
609
+
create foreign table lineitem_fdw (
610
+
l_suppkey int4 not null,
611
+
l_orderkey int4 not null,
612
+
l_partkey int4 not null,
613
+
l_shipdate date not null,
614
+
l_quantity float4 not null,
615
+
l_extendedprice float4 not null,
616
+
l_discount float4 not null,
617
+
l_tax float4 not null,
618
+
l_returnflag "char" not null,
619
+
l_linestatus "char" not null
620
+
) server vops_server options (table_name 'vops_lineitem');
0 commit comments