From 83f2d4aef2fcb9f817a543cf0f4e9235139b91ab Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Tue, 15 Sep 2020 17:30:19 -0700 Subject: [PATCH] more fixes --- cstore_tableam.c | 16 +++++++++++++++- expected/am_create.out | 9 ++++----- output/am_create.source | 9 ++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/cstore_tableam.c b/cstore_tableam.c index 09bc8e5e4..9478f86ae 100644 --- a/cstore_tableam.c +++ b/cstore_tableam.c @@ -458,7 +458,21 @@ cstore_index_validate_scan(Relation heapRelation, static uint64 cstore_relation_size(Relation rel, ForkNumber forkNumber) { - elog(ERROR, "cstore_relation_size not implemented"); + uint64 nblocks = 0; + + /* Open it at the smgr level if not already done */ + RelationOpenSmgr(rel); + + /* InvalidForkNumber indicates returning the size for all forks */ + if (forkNumber == InvalidForkNumber) + { + for (int i = 0; i < MAX_FORKNUM; i++) + nblocks += smgrnblocks(rel->rd_smgr, i); + } + else + nblocks = smgrnblocks(rel->rd_smgr, forkNumber); + + return nblocks * BLCKSZ; } static bool diff --git a/expected/am_create.out b/expected/am_create.out index 56a8b52af..e62447252 100644 --- a/expected/am_create.out +++ b/expected/am_create.out @@ -1,15 +1,14 @@ -- --- Test the CREATE statements related to cstore_fdw. +-- Test the CREATE statements related to cstore. -- --- Validator tests -- Create uncompressed table -CREATE FOREIGN TABLE contestant (handle TEXT, birthdate DATE, rating INT, +CREATE TABLE contestant (handle TEXT, birthdate DATE, rating INT, percentile FLOAT, country CHAR(3), achievements TEXT[]) USING cstore_tableam; -- Create compressed table with automatically determined file path -CREATE FOREIGN TABLE contestant_compressed (handle TEXT, birthdate DATE, rating INT, +CREATE TABLE contestant_compressed (handle TEXT, birthdate DATE, rating INT, percentile FLOAT, country CHAR(3), achievements TEXT[]) - USING cstore_tableam + USING cstore_tableam; -- Test that querying an empty table works ANALYZE contestant; SELECT count(*) FROM contestant; diff --git a/output/am_create.source b/output/am_create.source index 56a8b52af..e62447252 100644 --- a/output/am_create.source +++ b/output/am_create.source @@ -1,15 +1,14 @@ -- --- Test the CREATE statements related to cstore_fdw. +-- Test the CREATE statements related to cstore. -- --- Validator tests -- Create uncompressed table -CREATE FOREIGN TABLE contestant (handle TEXT, birthdate DATE, rating INT, +CREATE TABLE contestant (handle TEXT, birthdate DATE, rating INT, percentile FLOAT, country CHAR(3), achievements TEXT[]) USING cstore_tableam; -- Create compressed table with automatically determined file path -CREATE FOREIGN TABLE contestant_compressed (handle TEXT, birthdate DATE, rating INT, +CREATE TABLE contestant_compressed (handle TEXT, birthdate DATE, rating INT, percentile FLOAT, country CHAR(3), achievements TEXT[]) - USING cstore_tableam + USING cstore_tableam; -- Test that querying an empty table works ANALYZE contestant; SELECT count(*) FROM contestant;