Skip to content

Commit

Permalink
Fix coding by review, add regression test. Add resource owner check t…
Browse files Browse the repository at this point in the history
…o prevent apache#552-like issues
  • Loading branch information
reshke committed Aug 13, 2024
1 parent 41b3b8a commit ad87254
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/backend/commands/matview.c
Original file line number Diff line number Diff line change
Expand Up @@ -3291,16 +3291,28 @@ clean_up_IVM_hash_entry(MV_TriggerHashEntry *entry, bool is_abort)
{
MV_TriggerTable *table = (MV_TriggerTable *) lfirst(lc);

list_free(table->old_tuplestores);
list_free(table->new_tuplestores);
if (table->old_tuplestores) {
list_free(table->old_tuplestores);
table->old_tuplestores = NIL;
}

if (table->new_tuplestores) {
list_free(table->new_tuplestores);
table->new_tuplestores = NIL;
}
if (!is_abort)
{
ExecDropSingleTupleTableSlot(table->slot);
table_close(table->rel, NoLock);
if (CurrentResourceOwner == entry->resowner) {
ExecDropSingleTupleTableSlot(table->slot);
table_close(table->rel, NoLock);
}
}
}
list_free(entry->tables);

if (entry->tables) {
list_free(entry->tables);
entry->tables = NIL;
}
clean_up_ivm_dsm_entry(entry);

hash_search(mv_trigger_info, (void *) &entry->matview_id, HASH_REMOVE, NULL);
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

0 comments on commit ad87254

Please sign in to comment.