Skip to content

Commit b700d44

Browse files
author
Antonin Houska
committed
Implement handling of generated columns.
1 parent 3867a9c commit b700d44

File tree

6 files changed

+293
-67
lines changed

6 files changed

+293
-67
lines changed

expected/pg_rewrite.out

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,43 @@ SELECT i FROM tab6 ORDER BY i;
379379
2
380380
(2 rows)
381381

382+
-- Generated columns - some meaningful combinations of source and destination
383+
-- columns.
384+
CREATE TABLE tab7(
385+
i int primary key,
386+
j int,
387+
k int generated always as (i + 1) virtual,
388+
l int generated always AS (i + 1) virtual);
389+
CREATE TABLE tab7_new(
390+
i int primary key,
391+
-- Override the value copied from the source table.
392+
j int generated always AS (i - 1) stored,
393+
-- Check that the expression is evaluated correctly on the source
394+
-- table.
395+
k int,
396+
-- Override the value computed on the source table.
397+
l int generated always as (i - 1) virtual);
398+
INSERT INTO tab7(i, j) VALUES (1, 1);
399+
SELECT rewrite_table('tab7', 'tab7_new', 'tab7_orig');
400+
rewrite_table
401+
---------------
402+
403+
(1 row)
404+
405+
SELECT * FROM tab7 ORDER BY i;
406+
i | j | k | l
407+
---+---+---+---
408+
1 | 0 | 2 | 0
409+
(1 row)
410+
411+
CREATE EXTENSION pageinspect;
412+
-- HEAP_HASNULL indicates that the value of 'l' hasn't been copied from the
413+
-- source table.
414+
SELECT raw_flags
415+
FROM heap_page_items(get_raw_page('tab7', 0)),
416+
LATERAL heap_tuple_infomask_flags(t_infomask, t_infomask2);
417+
raw_flags
418+
------------------------------------------------------
419+
{HEAP_HASNULL,HEAP_XMIN_COMMITTED,HEAP_XMAX_INVALID}
420+
(1 row)
421+

expected/pg_rewrite_concurrent.out

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,20 @@ $$;
8080
step do_check:
8181
TABLE pg_rewrite_progress;
8282

83-
SELECT i, j FROM tbl_src ORDER BY i, j;
83+
SELECT i, j, k, l FROM tbl_src ORDER BY i, j;
8484

8585
src_table|dst_table|src_table_new|ins_initial|ins|upd|del
8686
---------+---------+-------------+-----------+---+---+---
8787
tbl_src |tbl_dst |tbl_src_old | 3| 3| 4| 1
8888
(1 row)
8989

90-
i| j
91-
-+--
92-
1| 0
93-
2| 8
94-
3|30
95-
5|50
96-
6|40
90+
i| j| k| l
91+
-+--+---+---
92+
1| 0| 0| 0
93+
2| 8| -8| -8
94+
3|30|-30|-30
95+
5|50|-50|-50
96+
6|40|-40|-40
9797
(5 rows)
9898

9999
step wakeup_after_commit_ip:

0 commit comments

Comments
 (0)