Hi,
I have two identically sorted (much bigger than huge) datasets, and need to combine them, keeping sort order.
Vertica do have a perfect facility to accomplish it - UNION ALL with SORT clause and corresponding hints
(SELECT * FROM t1 ORDER BY x)
UNION ALL
(SELECT * FROM t2 ORDER BY x)
SORT BY X;
When executed correctly, data is merged. Straight sorting of resultset would be around two orders of magnitude less performant.
Adding required hints:
create table t(c varchar(10), n varchar(10))
order by c
segmented by hash(c) all nodes;
insert into t values('A', 'B');
insert into t values('C', 'D');
(select /+ syntactic_join */ * from t order by c)
union all /+ UTYPE(M) */
(select * from t order by c)
order by c;
dbadmin=> (select /+ syntactic_join */ * from t order by c)
dbadmin-> union all /+ UTYPE(M) */
dbadmin-> (select * from t order by c)
dbadmin-> order by c;
WARNING 7134: Union type hints are not feasible and will be ignored
c | n
---+---
A | B
A | B
C | D
C | D
(4 rows)
Apparently, union type hint does not work. I remember it used to work just fine.
What I am doing wrong? Both rowsets are sorted on correct key, result sorted on correct key, hints are correct. Still, UNION ALL is doing concatenate instead of merging.
That is confirmed by explain:
explain
(select /+ syntactic_join */ * from t order by c)
union all /+ UTYPE(M) */
(select * from t order by c)
order by c;
Access Path:
+-SORT [Cost: 3K, Rows: 20K (NO STATISTICS)]
| Order: "SELECT 1".c ASC
| +---> UNION ALL [Cost: 2K, Rows: 20K (NO STATISTICS)]
| | +---> STORAGE ACCESS for t [Cost: 1K, Rows: 10K (NO STATISTICS)] (PATH ID: 2)
| | | Projection: public.t_super
| | | Materialize: t.c, t.n
| | +---> STORAGE ACCESS for t [Cost: 1K, Rows: 10K (NO STATISTICS)] (PATH ID: 5)
| | | Projection: public.t_super
| | | Materialize: t.c, t.n
What I am doing wrong - how to make UTYPE(M) work?