When multiple tables are updated or the view contains a self-join, we need to calculate table states that was before it is modified during incremental view maintenance. For get the pre-update state, tuples inserted in a command must be removed when the table is scanned. Previously, we used xmin and cmin system columns for this purpose, but this way is problematic because after a tuple is frozen, its xmin no longer has any meaning. Actually, we will get inconsistent view results after XID wraparound. Also, we can see similar similar inconsistency when using sub-transaction because xmin values do not always monotonically increasing by command executions. To fix this, we use a snapshot that taken just before the table is modified for checking tuple visibility in pre-state table instead of using xmin and cmin system columns. A new function returning boolean, ivm_visible_in_prestate, is added, and this is called in WHERE clause of sub-queries to calculate pre-state table. This function check if a specified tuple in the post-update table is visible or not using the snapshot and return true if the tuple is visible.
7 lines
149 B
SQL
7 lines
149 B
SQL
-- functions
|
|
|
|
CREATE FUNCTION ivm_visible_in_prestate(oid, tid, oid)
|
|
RETURNS bool
|
|
STABLE
|
|
AS 'MODULE_PATHNAME', 'ivm_visible_in_prestate'
|
|
LANGUAGE C;
|