From ec1e277e8ee7bb57b66e57476a8c707e33bec7a9 Mon Sep 17 00:00:00 2001 From: Hadi Moshayedi Date: Sat, 26 Sep 2020 23:50:23 -0700 Subject: [PATCH] Initial implementation of ANALYZE --- Makefile | 4 ++-- cstore_tableam.c | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index ea5a858bf..483aebc35 100644 --- a/Makefile +++ b/Makefile @@ -48,11 +48,11 @@ ifeq ($(USE_FDW),yes) fdw_copyto fdw_alter fdw_truncate fdw_clean endif -# disabled tests: am_block_filtering am_analyze +# disabled tests: am_block_filtering ifeq ($(USE_TABLEAM),yes) PG_CFLAGS += -DUSE_TABLEAM OBJS += cstore_tableam.o - REGRESS += am_create am_load am_query am_data_types am_functions \ + REGRESS += am_create am_load am_query am_analyze am_data_types am_functions \ am_drop am_insert am_copyto am_alter am_truncate am_clean endif diff --git a/cstore_tableam.c b/cstore_tableam.c index 312e10981..3f8c37db9 100644 --- a/cstore_tableam.c +++ b/cstore_tableam.c @@ -470,8 +470,13 @@ static bool cstore_scan_analyze_next_block(TableScanDesc scan, BlockNumber blockno, BufferAccessStrategy bstrategy) { - /* TODO */ - return false; + /* + * Our access method is not pages based, i.e. tuples are not confined + * to pages boundaries. So not much to do here. We return true anyway + * so acquire_sample_rows() in analyze.c would call our + * cstore_scan_analyze_next_tuple() callback. + */ + return true; } @@ -480,7 +485,23 @@ cstore_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin, double *liverows, double *deadrows, TupleTableSlot *slot) { - /* TODO */ + /* + * 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 + * based access methods where it chooses random pages, and then reads + * tuples from those pages. + * + * We could do something like that here by choosing sample stripes or blocks, + * but getting that correct might need quite some work. Since cstore_fdw's + * ANALYZE scanned all rows, as a starter we do the same here and scan all + * rows. + */ + if (cstore_getnextslot(scan, ForwardScanDirection, slot)) + { + (*liverows)++; + return true; + } + return false; }