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

[columnar] fixes a state where an explain with cache on can cause a crash #125

Merged
merged 1 commit into from
Aug 2, 2023
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
6 changes: 6 additions & 0 deletions columnar/src/backend/columnar/columnar_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ MemoryContext ColumnarCacheMemoryContext(void)
{
columnarCacheContext = AllocSetContextCreate(TopMemoryContext, "Columnar Decompression Cache", 0, (uint64) (columnar_page_cache_size * 1024 * 1024 * .1), columnar_page_cache_size * 1024 * 1024);
memset(&statistics, 0, sizeof(ColumnarCacheStatistics));
head = NULL;
}

return columnarCacheContext;
Expand Down Expand Up @@ -333,6 +334,11 @@ static uint64 ColumnarCacheLength()
{
uint64 count = 0;

if (head == NULL)
{
return 0;
}

dlist_iter iter;
dlist_foreach(iter, head)
{
Expand Down
5 changes: 5 additions & 0 deletions columnar/src/backend/columnar/columnar_tableam.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,11 @@ TruncateAndCombineColumnarStripes(Relation rel, int elevel)
startingStripeListPosition++;
}

if (startingStripeListPosition == 0)
{
return false;
}

/*
* There is only one stripe that is candidate. Maybe we should vacuum
* it if condition is met.
Expand Down
14 changes: 14 additions & 0 deletions columnar/src/test/regress/expected/columnar_cache.out
Original file line number Diff line number Diff line change
Expand Up @@ -3122,3 +3122,17 @@ SELECT SUM(value)

COMMIT;
DROP TABLE test_2;
CREATE TABLE t1 (i int) USING columnar;
INSERT INTO t1 SELECT generate_series(1, 1000000, 1);
EXPLAIN SELECT COUNT(*) FROM t1;
QUERY PLAN
-----------------------------------------------------------------------------------------------------
Finalize Aggregate (cost=1472.17..1472.18 rows=1 width=8)
-> Gather (cost=1471.54..1472.15 rows=6 width=8)
Workers Planned: 6
-> Partial Aggregate (cost=471.54..471.55 rows=1 width=8)
-> Parallel Custom Scan (ColumnarScan) on t1 (cost=0.00..54.88 rows=166667 width=0)
Columnar Projected Columns: <columnar optimized out all columns>
(6 rows)

DROP TABLE t1;
5 changes: 5 additions & 0 deletions columnar/src/test/regress/sql/columnar_cache.sql
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@ COMMIT;

DROP TABLE test_2;

CREATE TABLE t1 (i int) USING columnar;

INSERT INTO t1 SELECT generate_series(1, 1000000, 1);
EXPLAIN SELECT COUNT(*) FROM t1;
DROP TABLE t1;