Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with base relation truncate for IMMV #570

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/backend/commands/matview.c
Original file line number Diff line number Diff line change
Expand Up @@ -3301,6 +3301,22 @@ clean_up_IVM_hash_entry(MV_TriggerHashEntry *entry, bool is_abort)
list_free(table->new_tuplestores);
table->new_tuplestores = NIL;
}
if (!is_abort)
{
if (CurrentResourceOwner == entry->resowner)
{
if (table->slot)
{
ExecDropSingleTupleTableSlot(table->slot);
table->slot = NULL;
}
if (table->rel)
{
table_close(table->rel, NoLock);
table->rel = NULL;
}
}
}
}

if (entry->tables)
Expand Down
10 changes: 10 additions & 0 deletions src/test/regress/expected/incremental_matview.out
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ SELECT SUM(j), COUNT(j), AVG(j) FROM mv_base_a;
(1 row)

ROLLBACK;
-- TRUNCATE a base table without transaction block.
CREATE TABLE mv_base_simple(i int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Cloudberry Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE INCREMENTAL MATERIALIZED VIEW mv_ivm_simple AS SELECT * FROM mv_base_simple;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'i' as the Cloudberry Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
TRUNCATE mv_base_simple;
DROP TABLE mv_base_simple CASCADE;
NOTICE: drop cascades to materialized view mv_ivm_simple
-- resolved issue: When use AVG() function and values is indivisible, result of AVG() is incorrect.
BEGIN;
CREATE INCREMENTAL MATERIALIZED VIEW mv_ivm_avg_bug AS SELECT i, SUM(j), COUNT(j), AVG(j) FROM mv_base_A GROUP BY i;
Expand Down
6 changes: 6 additions & 0 deletions src/test/regress/sql/incremental_matview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ SELECT sum, count, avg FROM mv_ivm_group;
SELECT SUM(j), COUNT(j), AVG(j) FROM mv_base_a;
ROLLBACK;

-- TRUNCATE a base table without transaction block.
CREATE TABLE mv_base_simple(i int);
CREATE INCREMENTAL MATERIALIZED VIEW mv_ivm_simple AS SELECT * FROM mv_base_simple;
TRUNCATE mv_base_simple;
DROP TABLE mv_base_simple CASCADE;

-- resolved issue: When use AVG() function and values is indivisible, result of AVG() is incorrect.
BEGIN;
CREATE INCREMENTAL MATERIALIZED VIEW mv_ivm_avg_bug AS SELECT i, SUM(j), COUNT(j), AVG(j) FROM mv_base_A GROUP BY i;
Expand Down
Loading