diff --git a/cstore_tableam.c b/cstore_tableam.c index 21c1aab1f..09bc8e5e4 100644 --- a/cstore_tableam.c +++ b/cstore_tableam.c @@ -44,6 +44,7 @@ typedef struct CStoreScanDescData *CStoreScanDesc; static TableWriteState *CStoreWriteState = NULL; static ExecutorEnd_hook_type PreviousExecutorEndHook = NULL; +static MemoryContext CStoreContext = NULL; static CStoreOptions * CStoreGetDefaultOptions(void) @@ -71,13 +72,22 @@ cstore_init_write_state(Relation relation) { CStoreOptions *cstoreOptions = CStoreGetDefaultOptions(); TupleDesc tupdesc = RelationGetDescr(relation); + MemoryContext oldContext; + + if (CStoreContext == NULL) + { + CStoreContext = AllocSetContextCreate(TopMemoryContext, "cstore context", + ALLOCSET_DEFAULT_SIZES); + } elog(LOG, "initializing write state for relation %d", relation->rd_id); + oldContext = MemoryContextSwitchTo(CStoreContext); CStoreWriteState = CStoreBeginWrite(relation->rd_id, cstoreOptions->compressionType, cstoreOptions->stripeRowCount, cstoreOptions->blockRowCount, tupdesc); + MemoryContextSwitchTo(oldContext); CStoreWriteState->relation = relation; } diff --git a/expected/am_create.out b/expected/am_create.out index 961c0494d..56a8b52af 100644 --- a/expected/am_create.out +++ b/expected/am_create.out @@ -1,39 +1,15 @@ -- -- Test the CREATE statements related to cstore_fdw. -- --- Install cstore_fdw -CREATE EXTENSION cstore_fdw; -CREATE SERVER cstore_server FOREIGN DATA WRAPPER cstore_fdw; -- Validator tests -CREATE FOREIGN TABLE test_validator_invalid_option () - SERVER cstore_server - OPTIONS(bad_option_name '1'); -- ERROR -ERROR: invalid option "bad_option_name" -HINT: Valid options in this context are: compression, stripe_row_count, block_row_count -CREATE FOREIGN TABLE test_validator_invalid_stripe_row_count () - SERVER cstore_server - OPTIONS(stripe_row_count '0'); -- ERROR -ERROR: invalid stripe row count -HINT: Stripe row count must be an integer between 1000 and 10000000 -CREATE FOREIGN TABLE test_validator_invalid_block_row_count () - SERVER cstore_server - OPTIONS(block_row_count '0'); -- ERROR -ERROR: invalid block row count -HINT: Block row count must be an integer between 1000 and 100000 -CREATE FOREIGN TABLE test_validator_invalid_compression_type () - SERVER cstore_server - OPTIONS(compression 'invalid_compression'); -- ERROR -ERROR: invalid compression type -HINT: Valid options are: none, pglz -- Create uncompressed table CREATE FOREIGN TABLE contestant (handle TEXT, birthdate DATE, rating INT, percentile FLOAT, country CHAR(3), achievements TEXT[]) - SERVER cstore_server; + USING cstore_tableam; -- Create compressed table with automatically determined file path CREATE FOREIGN TABLE contestant_compressed (handle TEXT, birthdate DATE, rating INT, percentile FLOAT, country CHAR(3), achievements TEXT[]) - SERVER cstore_server - OPTIONS(compression 'pglz'); + USING cstore_tableam -- Test that querying an empty table works ANALYZE contestant; SELECT count(*) FROM contestant; diff --git a/input/am_block_filtering.source b/input/am_block_filtering.source index 0225bde16..7ca6862c7 100644 --- a/input/am_block_filtering.source +++ b/input/am_block_filtering.source @@ -29,8 +29,7 @@ $$ LANGUAGE PLPGSQL; -- Create and load data CREATE TABLE test_block_filtering (a int) - USING cstore_tableam - OPTIONS(block_row_count '1000', stripe_row_count '2000'); + USING cstore_tableam; COPY test_block_filtering FROM '@abs_srcdir@/data/block_filtering.csv' WITH CSV; diff --git a/output/am_create.source b/output/am_create.source index 961c0494d..56a8b52af 100644 --- a/output/am_create.source +++ b/output/am_create.source @@ -1,39 +1,15 @@ -- -- Test the CREATE statements related to cstore_fdw. -- --- Install cstore_fdw -CREATE EXTENSION cstore_fdw; -CREATE SERVER cstore_server FOREIGN DATA WRAPPER cstore_fdw; -- Validator tests -CREATE FOREIGN TABLE test_validator_invalid_option () - SERVER cstore_server - OPTIONS(bad_option_name '1'); -- ERROR -ERROR: invalid option "bad_option_name" -HINT: Valid options in this context are: compression, stripe_row_count, block_row_count -CREATE FOREIGN TABLE test_validator_invalid_stripe_row_count () - SERVER cstore_server - OPTIONS(stripe_row_count '0'); -- ERROR -ERROR: invalid stripe row count -HINT: Stripe row count must be an integer between 1000 and 10000000 -CREATE FOREIGN TABLE test_validator_invalid_block_row_count () - SERVER cstore_server - OPTIONS(block_row_count '0'); -- ERROR -ERROR: invalid block row count -HINT: Block row count must be an integer between 1000 and 100000 -CREATE FOREIGN TABLE test_validator_invalid_compression_type () - SERVER cstore_server - OPTIONS(compression 'invalid_compression'); -- ERROR -ERROR: invalid compression type -HINT: Valid options are: none, pglz -- Create uncompressed table CREATE FOREIGN TABLE contestant (handle TEXT, birthdate DATE, rating INT, percentile FLOAT, country CHAR(3), achievements TEXT[]) - SERVER cstore_server; + USING cstore_tableam; -- Create compressed table with automatically determined file path CREATE FOREIGN TABLE contestant_compressed (handle TEXT, birthdate DATE, rating INT, percentile FLOAT, country CHAR(3), achievements TEXT[]) - SERVER cstore_server - OPTIONS(compression 'pglz'); + USING cstore_tableam -- Test that querying an empty table works ANALYZE contestant; SELECT count(*) FROM contestant; diff --git a/sql/am_block_filtering.sql b/sql/am_block_filtering.sql index c7d0e997c..38c63535c 100644 --- a/sql/am_block_filtering.sql +++ b/sql/am_block_filtering.sql @@ -29,8 +29,7 @@ $$ LANGUAGE PLPGSQL; -- Create and load data CREATE TABLE test_block_filtering (a int) - USING cstore_tableam - OPTIONS(block_row_count '1000', stripe_row_count '2000'); + USING cstore_tableam; COPY test_block_filtering FROM '/Users/jefdavi/wd/cstore2/data/block_filtering.csv' WITH CSV; diff --git a/sql/am_functions.sql b/sql/am_functions.sql index 70624e6d4..a466d925d 100644 --- a/sql/am_functions.sql +++ b/sql/am_functions.sql @@ -12,8 +12,8 @@ COPY table_with_data FROM STDIN; 3 \. -SELECT cstore_table_size('empty_table') < cstore_table_size('table_with_data'); -SELECT cstore_table_size('non_cstore_table'); +SELECT pg_relation_size('empty_table') < cstore_table_size('table_with_data'); +SELECT pg_relation_size('non_cstore_table'); DROP TABLE empty_table; DROP TABLE table_with_data; diff --git a/sql/am_truncate.sql b/sql/am_truncate.sql index cc02c1805..e124a7831 100644 --- a/sql/am_truncate.sql +++ b/sql/am_truncate.sql @@ -9,7 +9,7 @@ SELECT substring(:'server_version', '\d+')::int > 10 AS version_above_ten; -- CREATE a cstore_fdw table, fill with some data -- CREATE TABLE cstore_truncate_test (a int, b int) USING cstore_tableam; CREATE TABLE cstore_truncate_test_second (a int, b int) USING cstore_tableam; -CREATE TABLE cstore_truncate_test_compressed (a int, b int) USING cstore_tableam OPTIONS (compression 'pglz'); +CREATE TABLE cstore_truncate_test_compressed (a int, b int) USING cstore_tableam; CREATE TABLE cstore_truncate_test_regular (a int, b int); INSERT INTO cstore_truncate_test select a, a from generate_series(1, 10) a; @@ -30,7 +30,7 @@ SELECT count(*) FROM cstore_truncate_test_compressed; TRUNCATE TABLE cstore_truncate_test_compressed; SELECT count(*) FROM cstore_truncate_test_compressed; -SELECT cstore_table_size('cstore_truncate_test_compressed'); +SELECT pg_relation_size('cstore_truncate_test_compressed'); INSERT INTO cstore_truncate_test select a, a from generate_series(1, 10) a; INSERT INTO cstore_truncate_test_regular select a, a from generate_series(10, 20) a; @@ -76,7 +76,7 @@ DROP TABLE cstore_truncate_test_compressed; -- test truncate with schema CREATE SCHEMA truncate_schema; -CREATE TABLE truncate_schema.truncate_tbl (id int) USING cstore_tableam OPTIONS(compression 'pglz'); +CREATE TABLE truncate_schema.truncate_tbl (id int) USING cstore_tableam; INSERT INTO truncate_schema.truncate_tbl SELECT generate_series(1, 100); SELECT COUNT(*) FROM truncate_schema.truncate_tbl; diff --git a/sql/clean.sql b/sql/clean.sql index 2e038d321..3375ebeb6 100644 --- a/sql/clean.sql +++ b/sql/clean.sql @@ -1,4 +1,5 @@ +DROP TABLE test_block_filtering; DROP TABLE test_insert_command; DROP TABLE collation_block_filtering_test; DROP TABLE test_null_values;