diff --git a/columnar/src/backend/columnar/columnar_tableam.c b/columnar/src/backend/columnar/columnar_tableam.c index 456ba8c..11eb029 100644 --- a/columnar/src/backend/columnar/columnar_tableam.c +++ b/columnar/src/backend/columnar/columnar_tableam.c @@ -1650,6 +1650,10 @@ static void columnar_vacuum_rel(Relation rel, VacuumParams *params, BufferAccessStrategy bstrategy) { + /* Capture the cache state and disable it for a vacuum. */ + bool old_cache_mode = columnar_enable_page_cache; + columnar_enable_page_cache = false; + pgstat_progress_start_command(PROGRESS_COMMAND_VACUUM, RelationGetRelid(rel)); @@ -1779,6 +1783,9 @@ columnar_vacuum_rel(Relation rel, VacuumParams *params, Max(new_live_tuples, 0), 0); pgstat_progress_end_command(); + + /* Reenable the cache state. */ + columnar_enable_page_cache = old_cache_mode; } @@ -2074,6 +2081,10 @@ columnar_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin, double *liverows, double *deadrows, TupleTableSlot *slot) { + /* Capture the cache state and disable it for a vacuum. */ + bool old_cache_mode = columnar_enable_page_cache; + columnar_enable_page_cache = false; + /* * Currently we don't do anything smart to reduce number of rows returned * for ANALYZE. The TableAM API's ANALYZE functions are designed for page @@ -2088,9 +2099,16 @@ columnar_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin, if (columnar_getnextslot(scan, ForwardScanDirection, slot)) { (*liverows)++; + + /* Reset cache to previous state. */ + columnar_enable_page_cache = old_cache_mode; + return true; } + /* Reset cache to previous state. */ + columnar_enable_page_cache = old_cache_mode; + return false; } @@ -2126,6 +2144,10 @@ columnar_index_build_range_scan(Relation columnarRelation, elog(ERROR, "parallel scans on columnar are not supported"); } + /* Disable the page cache for the index build. */ + bool old_cache_mode = columnar_enable_page_cache; + columnar_enable_page_cache = false; + /* * In a normal index build, we use SnapshotAny to retrieve all tuples. In * a concurrent build or during bootstrap, we take a regular MVCC snapshot @@ -2199,6 +2221,9 @@ columnar_index_build_range_scan(Relation columnarRelation, indexInfo->ii_ExpressionsState = NIL; indexInfo->ii_PredicateState = NULL; + /* Reset the cache mode. */ + columnar_enable_page_cache = old_cache_mode; + return reltuples; } @@ -3481,6 +3506,10 @@ vacuum_columnar_table(PG_FUNCTION_ARGS) bool completelyDone = false; struct sigaction action; + /* Capture the cache state and disable it for a vacuum. */ + bool old_cache_mode = columnar_enable_page_cache; + columnar_enable_page_cache = false; + /* * Set up signal handlers for any incoming signals during the vacuum, * killing during a write could cause corruption. Give us time to @@ -3512,6 +3541,9 @@ vacuum_columnar_table(PG_FUNCTION_ARGS) MemoryContextSwitchTo(oldcontext); + /* Reset cache to previous state. */ + columnar_enable_page_cache = old_cache_mode; + PG_RETURN_VOID(); } @@ -3541,6 +3573,9 @@ vacuum_columnar_table(PG_FUNCTION_ARGS) MemoryContextSwitchTo(oldcontext); + /* Reset cache to previous state. */ + columnar_enable_page_cache = old_cache_mode; + PG_RETURN_VOID(); } @@ -3691,6 +3726,9 @@ vacuum_columnar_table(PG_FUNCTION_ARGS) kil_action.sa_handler(SIGKILL); } + /* Reset cache to previous state. */ + columnar_enable_page_cache = old_cache_mode; + PG_RETURN_NULL(); } @@ -3716,6 +3754,10 @@ vacuum_columnar_table(PG_FUNCTION_ARGS) relation_close(rel, NoLock); TruncateColumnar(rel, DEBUG3); UnlockRelation(rel, ExclusiveLock); + + /* Reset cache to previous state. */ + columnar_enable_page_cache = old_cache_mode; + PG_RETURN_UINT32(progress); } @@ -3764,6 +3806,9 @@ vacuum_columnar_table(PG_FUNCTION_ARGS) kil_action.sa_handler(SIGKILL); } + /* Reset cache to previous state. */ + columnar_enable_page_cache = old_cache_mode; + PG_RETURN_NULL(); } @@ -3857,6 +3902,9 @@ vacuum_columnar_table(PG_FUNCTION_ARGS) sigaction(SIGABRT, &abt_action, NULL); sigaction(SIGKILL, &kil_action, NULL); + /* Reset cache to previous state. */ + columnar_enable_page_cache = old_cache_mode; + PG_RETURN_UINT32(progress + relocationProgress); } diff --git a/columnar/src/test/regress/expected/columnar_indexes.out b/columnar/src/test/regress/expected/columnar_indexes.out index 66aad1f..35a519a 100644 --- a/columnar/src/test/regress/expected/columnar_indexes.out +++ b/columnar/src/test/regress/expected/columnar_indexes.out @@ -796,5 +796,19 @@ BEGIN; (1 row) ROLLBACK; +CREATE TABLE test_cache ( + i INT, t TEXT +) USING columnar; +INSERT INTO test_cache SELECT generate_series(1, 100, 1) AS i, generate_series(1, 100, 1)::TEXT AS t; +SET columnar.enable_column_cache = 't'; +CREATE INDEX ON test_cache (i); +-- should be true +SHOW columnar.enable_column_cache; + columnar.enable_column_cache +------------------------------ + on +(1 row) + +DROP TABLE test_cache; SET client_min_messages TO WARNING; DROP SCHEMA columnar_indexes CASCADE; diff --git a/columnar/src/test/regress/expected/columnar_vacuum.out b/columnar/src/test/regress/expected/columnar_vacuum.out index 6d83db2..101d9d3 100644 --- a/columnar/src/test/regress/expected/columnar_vacuum.out +++ b/columnar/src/test/regress/expected/columnar_vacuum.out @@ -472,3 +472,20 @@ SELECT COUNT(*) = 4 FROM columnar.stripe WHERE storage_id = :t_oid; (1 row) DROP TABLE t; +CREATE TABLE cache_test (i INT) USING columnar; +INSERT INTO cache_test SELECT generate_series(1, 100, 1); +SET columnar.enable_column_cache = 't'; +SELECT columnar.vacuum('cache_test'); + vacuum +-------- + 0 +(1 row) + +-- should be true +SHOW columnar.enable_column_cache; + columnar.enable_column_cache +------------------------------ + on +(1 row) + +DROP TABLE cache_test; diff --git a/columnar/src/test/regress/expected/columnar_vacuum_udf.out b/columnar/src/test/regress/expected/columnar_vacuum_udf.out index 471fa14..d9b575a 100644 --- a/columnar/src/test/regress/expected/columnar_vacuum_udf.out +++ b/columnar/src/test/regress/expected/columnar_vacuum_udf.out @@ -366,3 +366,23 @@ SELECT count(i1), count(i2), count(i3), count(i4) FROM t1; (1 row) DROP TABLE t1; +CREATE TABLE cache_test (i INT) USING columnar; +INSERT INTO cache_test SELECT generate_series(1, 100, 1); +SET columnar.enable_column_cache = 't'; +VACUUM cache_test; +-- should be true +SHOW columnar.enable_column_cache; + columnar.enable_column_cache +------------------------------ + on +(1 row) + +ANALYZE cache_test; +-- should be true +SHOW columnar.enable_column_cache; + columnar.enable_column_cache +------------------------------ + on +(1 row) + +DROP TABLE cache_test; diff --git a/columnar/src/test/regress/sql/columnar_indexes.sql b/columnar/src/test/regress/sql/columnar_indexes.sql index 342eaae..003b0c0 100644 --- a/columnar/src/test/regress/sql/columnar_indexes.sql +++ b/columnar/src/test/regress/sql/columnar_indexes.sql @@ -642,6 +642,18 @@ BEGIN; SELECT COUNT(*) FROM circles_and_stuff; -- should return 1 ROLLBACK; +CREATE TABLE test_cache ( + i INT, t TEXT +) USING columnar; +INSERT INTO test_cache SELECT generate_series(1, 100, 1) AS i, generate_series(1, 100, 1)::TEXT AS t; + +SET columnar.enable_column_cache = 't'; + +CREATE INDEX ON test_cache (i); +-- should be true +SHOW columnar.enable_column_cache; + +DROP TABLE test_cache; SET client_min_messages TO WARNING; DROP SCHEMA columnar_indexes CASCADE; diff --git a/columnar/src/test/regress/sql/columnar_vacuum.sql b/columnar/src/test/regress/sql/columnar_vacuum.sql index be58c99..07b27ac 100644 --- a/columnar/src/test/regress/sql/columnar_vacuum.sql +++ b/columnar/src/test/regress/sql/columnar_vacuum.sql @@ -269,3 +269,14 @@ VACUUM t; SELECT COUNT(*) = 4 FROM columnar.stripe WHERE storage_id = :t_oid; DROP TABLE t; + +CREATE TABLE cache_test (i INT) USING columnar; +INSERT INTO cache_test SELECT generate_series(1, 100, 1); + +SET columnar.enable_column_cache = 't'; +SELECT columnar.vacuum('cache_test'); + +-- should be true +SHOW columnar.enable_column_cache; + +DROP TABLE cache_test; diff --git a/columnar/src/test/regress/sql/columnar_vacuum_udf.sql b/columnar/src/test/regress/sql/columnar_vacuum_udf.sql index b026ea5..4a6a8dd 100644 --- a/columnar/src/test/regress/sql/columnar_vacuum_udf.sql +++ b/columnar/src/test/regress/sql/columnar_vacuum_udf.sql @@ -89,3 +89,19 @@ SELECT columnar.vacuum('t1'); SELECT count(i1), count(i2), count(i3), count(i4) FROM t1; DROP TABLE t1; + +CREATE TABLE cache_test (i INT) USING columnar; +INSERT INTO cache_test SELECT generate_series(1, 100, 1); + +SET columnar.enable_column_cache = 't'; +VACUUM cache_test; + +-- should be true +SHOW columnar.enable_column_cache; + +ANALYZE cache_test; + +-- should be true +SHOW columnar.enable_column_cache; + +DROP TABLE cache_test;