Use snapshot to check tuple visibility in pre-update state (#28)
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.
2022-09-30 02:53:12 +00:00
|
|
|
-- functions
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION ivm_visible_in_prestate(oid, tid, oid)
|
|
|
|
|
RETURNS bool
|
|
|
|
|
STABLE
|
|
|
|
|
AS 'MODULE_PATHNAME', 'ivm_visible_in_prestate'
|
|
|
|
|
LANGUAGE C;
|
2022-09-30 09:59:51 +00:00
|
|
|
|
|
|
|
|
CREATE FUNCTION get_immv_def(IN immvrelid regclass)
|
|
|
|
|
RETURNS text
|
|
|
|
|
STRICT
|
|
|
|
|
AS 'MODULE_PATHNAME', 'get_immv_def'
|
|
|
|
|
LANGUAGE C;
|
2022-09-30 14:49:51 +00:00
|
|
|
|
|
|
|
|
-- event trigger
|
|
|
|
|
|
|
|
|
|
DROP EVENT TRIGGER pg_ivm_sql_drop_trigger;
|
|
|
|
|
DROP FUNCTION pg_ivm_sql_drop_trigger_func;
|