Skip to content
Closed
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
4 changes: 2 additions & 2 deletions src/backend/access/aocs/aocsam.c
Original file line number Diff line number Diff line change
Expand Up @@ -1564,8 +1564,8 @@ aocs_fetch_init(Relation relation,
visimaprelid,
visimapidxid,
AccessShareLock,
appendOnlyMetaDataSnapshot);

InvalidSnapshot);
return aocsFetchDesc;
}

Expand Down
14 changes: 11 additions & 3 deletions src/backend/access/aocs/aocsam_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ aoco_index_fetch_tuple(struct IndexFetchTableData *scan,
bool *call_again, bool *all_dead)
{
IndexFetchAOCOData *aocoscan = (IndexFetchAOCOData *) scan;
bool found = false;

if (!aocoscan->aocofetch)
{
Expand Down Expand Up @@ -740,15 +741,19 @@ aoco_index_fetch_tuple(struct IndexFetchTableData *scan,
*/
Assert(aocoscan->aocofetch->snapshot == snapshot);

aocoscan->aocofetch->visibilityMap.visimapStore.snapshot = snapshot;

ExecClearTuple(slot);

if (aocs_fetch(aocoscan->aocofetch, (AOTupleId *) tid, slot))
{
ExecStoreVirtualTuple(slot);
return true;
found = true;
}

return false;
aocoscan->aocofetch->visibilityMap.visimapStore.snapshot = InvalidSnapshot;

return found;
}

static void
Expand Down Expand Up @@ -1808,6 +1813,8 @@ aoco_scan_bitmap_next_tuple(TableScanDesc scan,
aocsBitmapScan->bitmapScanDesc[aocsBitmapScan->whichDesc].bitmapFetch = aocoFetchDesc;
}

aocoFetchDesc->visibilityMap.visimapStore.snapshot = aocsBitmapScan->appendOnlyMetaDataSnapshot;

ExecClearTuple(slot);

/* ntuples == -1 indicates a lossy page */
Expand Down Expand Up @@ -1842,11 +1849,12 @@ aoco_scan_bitmap_next_tuple(TableScanDesc scan,
/* OK to return this tuple */
ExecStoreVirtualTuple(slot);
pgstat_count_heap_fetch(aocsBitmapScan->rs_base.rs_rd);
aocoFetchDesc->visibilityMap.visimapStore.snapshot = InvalidSnapshot;

return true;
}
}

aocoFetchDesc->visibilityMap.visimapStore.snapshot = InvalidSnapshot;
/* Done with this block */
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/access/appendonly/appendonlyam.c
Original file line number Diff line number Diff line change
Expand Up @@ -2281,7 +2281,7 @@ appendonly_fetch_init(Relation relation,
aoFormData.visimaprelid,
aoFormData.visimapidxid,
AccessShareLock,
appendOnlyMetaDataSnapshot);
InvalidSnapshot);

return aoFetchDesc;

Expand Down
9 changes: 8 additions & 1 deletion src/backend/access/appendonly/appendonlyam_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,12 @@ appendonly_index_fetch_tuple(struct IndexFetchTableData *scan,
*/
Assert(aoscan->aofetch->snapshot == snapshot);

aoscan->aofetch->visibilityMap.visimapStore.snapshot = snapshot;

appendonly_fetch(aoscan->aofetch, (AOTupleId *) tid, slot);

aoscan->aofetch->visibilityMap.visimapStore.snapshot = InvalidSnapshot;

return !TupIsNull(slot);
Comment on lines +548 to 554
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. set/reset at fetching each index tuple, we usually have million/billion of rows, and the set/rest cost will be double.
That's not great.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion, I think it is not great, too. But it works....

  1. we have already try another easy way to solve this problem, by removing register snapshot. But failed in CI test and trying to fix it. FIX: constraint check exception with snapshot memory leak in AO/AOCS #136
  2. we see the same way to slove the problem in unique index check by set/reset. And I think AO may not efficent in index fetch, so millions tuple index scan may not efficient for index fetch even without set and reset
  3. beg your better way to solve this problem, thanks.

}

Expand Down Expand Up @@ -1974,6 +1978,8 @@ appendonly_scan_bitmap_next_tuple(TableScanDesc scan,

}

aoscan->aofetch->visibilityMap.visimapStore.snapshot = aoscan->appendOnlyMetaDataSnapshot;

ExecClearTuple(slot);

/* ntuples == -1 indicates a lossy page */
Expand Down Expand Up @@ -2007,11 +2013,12 @@ appendonly_scan_bitmap_next_tuple(TableScanDesc scan,
{
/* OK to return this tuple */
pgstat_count_heap_fetch(aoscan->aos_rd);
aoscan->aofetch->visibilityMap.visimapStore.snapshot = InvalidSnapshot;

return true;
}
}

aoscan->aofetch->visibilityMap.visimapStore.snapshot = InvalidSnapshot;
/* Done with this block */
return false;
}
Expand Down
32 changes: 32 additions & 0 deletions src/test/regress/input/constraints.source
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,35 @@ DROP DOMAIN constraint_comments_dom;

DROP ROLE regress_constraint_comments;
DROP ROLE regress_constraint_comments_noaccess;

--
-- EXCLUDE constraints for AO
--
CREATE TABLE test_exclude_ao(
id int4,
room int4range,
EXCLUDE USING gist (room WITH =)
) USING AO_ROW DISTRIBUTED REPLICATED;
INSERT INTO test_exclude_ao VALUES(1, int4range(123, 123, '[]'));

-- conflicting key value violates exclusion constraint
-- expected conflicting key error without other exception happen
INSERT INTO test_exclude_ao VALUES(1, int4range(123, 123, '[]'));

DROP TABLE test_exclude_ao;

--
-- EXCLUDE constraints for AOCS
--
CREATE TABLE test_exclude_aocs(
id int4,
room int4range,
EXCLUDE USING gist (room WITH =)
) USING AO_COLUMN DISTRIBUTED REPLICATED;
INSERT INTO test_exclude_aocs VALUES(1, int4range(123, 123, '[]'));

-- conflicting key value violates exclusion constraint
-- expected conflicting key error without other exception happen
INSERT INTO test_exclude_aocs VALUES(1, int4range(123, 123, '[]'));

DROP TABLE test_exclude_aocs;
30 changes: 30 additions & 0 deletions src/test/regress/output/constraints.source
Original file line number Diff line number Diff line change
Expand Up @@ -779,3 +779,33 @@ DROP TABLE constraint_comments_tbl;
DROP DOMAIN constraint_comments_dom;
DROP ROLE regress_constraint_comments;
DROP ROLE regress_constraint_comments_noaccess;
--
-- EXCLUDE constraints for AO
--
CREATE TABLE test_exclude_ao(
id int4,
room int4range,
EXCLUDE USING gist (room WITH =)
) USING AO_ROW DISTRIBUTED REPLICATED;
INSERT INTO test_exclude_ao VALUES(1, int4range(123, 123, '[]'));
-- conflicting key value violates exclusion constraint
-- expected conflicting key error without other exception happen
INSERT INTO test_exclude_ao VALUES(1, int4range(123, 123, '[]'));
DETAIL: Key (room)=([123,124)) conflicts with existing key (room)=([123,124)).
ERROR: conflicting key value violates exclusion constraint "test_exclude_ao_room_excl"
DROP TABLE test_exclude_ao;
--
-- EXCLUDE constraints for AOCS
--
CREATE TABLE test_exclude_aocs(
id int4,
room int4range,
EXCLUDE USING gist (room WITH =)
) USING AO_COLUMN DISTRIBUTED REPLICATED;
INSERT INTO test_exclude_aocs VALUES(1, int4range(123, 123, '[]'));
-- conflicting key value violates exclusion constraint
-- expected conflicting key error without other exception happen
INSERT INTO test_exclude_aocs VALUES(1, int4range(123, 123, '[]'));
DETAIL: Key (room)=([123,124)) conflicts with existing key (room)=([123,124)).
ERROR: conflicting key value violates exclusion constraint "test_exclude_aocs_room_excl"
DROP TABLE test_exclude_aocs;