From a2639f51b911415c6eff3d2b965f785fe1024ea6 Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Fri, 31 Oct 2025 13:46:31 +0300 Subject: [PATCH 01/14] Add the temp_tables_stat extension --- .github/workflows/build-gpdb.yml | 3 + gpcontrib/Makefile | 6 +- gpcontrib/temp_tables_stat/Makefile | 20 + .../temp_tables_stat--0.1.sql | 8 + gpcontrib/temp_tables_stat/temp_tables_stat.c | 361 +++++ .../temp_tables_stat/temp_tables_stat.control | 5 + src/test/isolation2/Makefile | 2 + .../isolation2/expected/temp_tables_stat.out | 1380 +++++++++++++++++ src/test/isolation2/sql/temp_tables_stat.sql | 464 ++++++ 9 files changed, 2247 insertions(+), 2 deletions(-) create mode 100644 gpcontrib/temp_tables_stat/Makefile create mode 100644 gpcontrib/temp_tables_stat/temp_tables_stat--0.1.sql create mode 100644 gpcontrib/temp_tables_stat/temp_tables_stat.c create mode 100644 gpcontrib/temp_tables_stat/temp_tables_stat.control create mode 100644 src/test/isolation2/expected/temp_tables_stat.out create mode 100644 src/test/isolation2/sql/temp_tables_stat.sql diff --git a/.github/workflows/build-gpdb.yml b/.github/workflows/build-gpdb.yml index 90e9e7bb37b..977d8c0bad6 100644 --- a/.github/workflows/build-gpdb.yml +++ b/.github/workflows/build-gpdb.yml @@ -166,6 +166,9 @@ jobs: {"test":"ic-parallel-retrieve-cursor", "make_configs":["src/test/isolation2:installcheck-parallel-retrieve-cursor"] }, + {"test":"ic-temp_tables_stat", + "make_configs":["src/test/isolation2:installcheck-tts"] + }, {"test":"ic-mirrorless", "make_configs":["src/test/isolation2:installcheck-mirrorless"] }, diff --git a/gpcontrib/Makefile b/gpcontrib/Makefile index 9665ceed10c..4754040669d 100644 --- a/gpcontrib/Makefile +++ b/gpcontrib/Makefile @@ -27,7 +27,8 @@ ifeq "$(enable_debug_extensions)" "yes" gp_subtransaction_overflow \ gp_check_functions \ gp_aux_catalog \ - gp_interconnect_stats + gp_interconnect_stats \ + temp_tables_stat else recurse_targets = gp_sparse_vector \ gp_distribution_policy \ @@ -43,7 +44,8 @@ else gp_subtransaction_overflow \ gp_check_functions \ gp_aux_catalog \ - gp_interconnect_stats + gp_interconnect_stats \ + temp_tables_stat endif ifeq "$(with_zstd)" "yes" diff --git a/gpcontrib/temp_tables_stat/Makefile b/gpcontrib/temp_tables_stat/Makefile new file mode 100644 index 00000000000..df1644727cf --- /dev/null +++ b/gpcontrib/temp_tables_stat/Makefile @@ -0,0 +1,20 @@ +# gpcontrib/temp_tables_stat/Makefile + +MODULE_big = temp_tables_stat +OBJS = $(MODULE_big).o $(WIN32RES) + +EXTENSION = $(MODULE_big) +PGFILEDESC = "Collect and show statictics on temporary tables" + +DATA = $(MODULE_big)--0.1.sql + +ifdef USE_PGXS +PG_CONFIG = pg_config +PGXS := $(shell $(PG_CONFIG) --pgxs) +include $(PGXS) +else +subdir = gpcontrib/temp_tables_stat +top_builddir = ../.. +include $(top_builddir)/src/Makefile.global +include $(top_srcdir)/contrib/contrib-global.mk +endif diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat--0.1.sql b/gpcontrib/temp_tables_stat/temp_tables_stat--0.1.sql new file mode 100644 index 00000000000..00b9a2b7eac --- /dev/null +++ b/gpcontrib/temp_tables_stat/temp_tables_stat--0.1.sql @@ -0,0 +1,8 @@ +-- complain if script is sourced in psql, rather than via CREATE EXTENSION +\echo Use "CREATE EXTENSION temp_tables_stat" to load this file. \quit + +CREATE FUNCTION tts_get_seg_files(OUT user_id oid, OUT sess_id int4, OUT path text, OUT content int2, OUT size int8) +RETURNS SETOF RECORD +AS 'MODULE_PATHNAME', 'tts_get_seg_files' +LANGUAGE C +EXECUTE ON ALL SEGMENTS; diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat.c b/gpcontrib/temp_tables_stat/temp_tables_stat.c new file mode 100644 index 00000000000..7a16da1015f --- /dev/null +++ b/gpcontrib/temp_tables_stat/temp_tables_stat.c @@ -0,0 +1,361 @@ +#include "postgres.h" + +#include + +#include "cdb/cdbvars.h" +#include "funcapi.h" +#include "pgstat.h" +#include "storage/dsm.h" +#include "storage/ipc.h" +#include "utils/builtins.h" + +PG_MODULE_MAGIC; + +void _PG_init(void); +void _PG_fini(void); + +static file_create_hook_type prev_file_create_hook = NULL; +static file_unlink_hook_type prev_file_unlink_hook = NULL; +static shmem_startup_hook_type prev_shmem_startup_hook = NULL; + +/* + * RelFileNodeBackend-s for each temp table are stored in the list of arrays. + * The list is located in shared memory. The head node of the list (TTSHeadNode) + * is allocated using ShmemInitStruct. Next nodes (TTSNode) are allocated using + * DSM. The next node is created when array of RelFileNodeBackend-s in + * the previous one is full. It is assumed that array in the head node is large + * enough to contain all RelFileNodeBackend-s in normal case and DSM is used + * very rarely. + */ + +typedef struct TTSNode +{ + dsm_handle next; /* Handle of DSM segment with the next node */ + int num; /* Number of elements in files */ + RelFileNodeBackend files[1000000]; +} TTSNode; + +typedef struct TTSHeadNode +{ + LWLock lock; + TTSNode node; +} TTSHeadNode; + +static TTSHeadNode *head = NULL; /* Head of the list */ + +/* Get next node by current one */ +static TTSNode * +next_node(const TTSNode *node) +{ + dsm_segment *dsm_seg; + + if (node->next == DSM_HANDLE_INVALID) + return NULL; + + dsm_seg = dsm_find_mapping(node->next); + if (dsm_seg == NULL) + { + dsm_seg = dsm_attach(node->next); + dsm_pin_mapping(dsm_seg); + } + + return dsm_segment_address(dsm_seg); +} + +/* + * This function is called with the same argument when each fork is created. + * Add file info to the list if it is not there. + */ +static void +tts_file_create_hook(RelFileNodeBackend rnode) +{ + TTSNode *node; + + if (prev_file_create_hook) + (*prev_file_create_hook)(rnode); + + if (!RelFileNodeBackendIsTemp(rnode)) + return; + + rnode.backend = MyBackendId; + + LWLockAcquire(&head->lock, LW_EXCLUSIVE); + + /* Don't add rnode when it exists in the list of arrays */ + for (node = &head->node;; node = next_node(node)) + { + for (int i = 0; i < node->num; i++) + if (RelFileNodeBackendEquals(rnode, node->files[i])) + goto lExit; + + if (node->next == DSM_HANDLE_INVALID) + break; + } + + /* Create a new node if the last node is full */ + if (node->num == ARRAY_SIZE(node->files)) + { + dsm_segment *next_seg = dsm_create(sizeof(TTSNode)); + dsm_pin_mapping(next_seg); + node->next = dsm_segment_handle(next_seg); + node = dsm_segment_address(next_seg); + node->next = DSM_HANDLE_INVALID; + node->num = 0; + } + + node->files[node->num++] = rnode; + +lExit: + LWLockRelease(&head->lock); +} + +/* This function is called once for all forks. Delete file info from the list */ +static void +tts_file_unlink_hook(RelFileNodeBackend rnode) +{ + if (prev_file_unlink_hook) + (*prev_file_unlink_hook)(rnode); + + if (!RelFileNodeBackendIsTemp(rnode)) + return; + + rnode.backend = MyBackendId; + LWLockAcquire(&head->lock, LW_EXCLUSIVE); + + /* + * Find rnode in the list of arrays, replace rnode with the last element, + * decrement array length. + */ + for (TTSNode *node = &head->node, *prev_node = NULL; + node != NULL; + prev_node = node, node = next_node(node)) + { + for (int i = 0; i < node->num; i++) + if (RelFileNodeBackendEquals(rnode, node->files[i])) + { + /* Find the last node */ + TTSNode *last_node = node, *last_prev_node = prev_node; + while (last_node->next != DSM_HANDLE_INVALID) + { + last_prev_node = last_node; + last_node = next_node(last_node); + } + + node->files[i] = last_node->files[last_node->num - 1]; + + if (last_node->num > 1) + last_node->num--; + else if (last_node == &head->node) + head->node.num = 0; + else + { + /* + * last_prev_node != NULL because last_node is not head. + * next_node() has been called, so the mapping exists. + */ + dsm_detach(dsm_find_mapping(last_prev_node->next)); + last_prev_node->next = DSM_HANDLE_INVALID; + } + + goto lExit; + } + } + +lExit: + LWLockRelease(&head->lock); +} + +/* Postmaster creates a new shared memory space for the head node of the list */ +static void +tts_shmem_startup(void) +{ + bool found; + + if (prev_shmem_startup_hook) + (*prev_shmem_startup_hook)(); + + head = ShmemInitStruct("temp_tables_stat", sizeof(TTSHeadNode), &found); + if (found) + return; + + LWLockInitialize(&head->lock, 0); + head->node.next = DSM_HANDLE_INVALID; + head->node.num = 0; +} + +/* + * Get size of all files from the dirname directory, which names start + * with fn_start + */ +static int64 +tts_get_file_size(const char *dirname, const char *fn_start) +{ + struct dirent *direntry; + int64 dirsize = 0; + const size_t fn_start_len = strlen(fn_start); + DIR *dirdesc = AllocateDir(dirname); + + if (!dirdesc) + return 0; + + while ((direntry = ReadDir(dirdesc, dirname)) != NULL) + { + struct stat fst; + char fn[MAXPGPATH * 2]; + + CHECK_FOR_INTERRUPTS(); + + if (strcmp(direntry->d_name, ".") == 0 || + strcmp(direntry->d_name, "..") == 0 || + strncmp(direntry->d_name, fn_start, fn_start_len) != 0) + continue; + + snprintf(fn, sizeof(fn), "%s/%s", dirname, direntry->d_name); + + if (stat(fn, &fst) < 0) + { + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not stat file \"%s\": %m", fn))); + } + dirsize += fst.st_size; + } + + FreeDir(dirdesc); + return dirsize; +} + +/* Get temp tables files list on segments */ +PG_FUNCTION_INFO_V1(tts_get_seg_files); +Datum +tts_get_seg_files(PG_FUNCTION_ARGS) +{ + enum { NATTR = 5 }; + + FuncCallContext *funcctx; + PgBackendStatus *beStatus; + RelFileNodeBackend *file; + char *sep; + char *path; + HeapTuple tuple; + Datum values[NATTR] = {0}; + bool nulls [NATTR] = {0}; + static PgBackendStatus *beStatuses = NULL; + + if (SRF_IS_FIRSTCALL()) + { + MemoryContext oldcontext; + TupleDesc tupdesc; + RelFileNodeBackend *files; + int files_num = 0; + + funcctx = SRF_FIRSTCALL_INIT(); + + oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + + tupdesc = CreateTemplateTupleDesc(NATTR, false); + TupleDescInitEntry(tupdesc, (AttrNumber) 1, "user_id", OIDOID, -1, 0); + TupleDescInitEntry(tupdesc, (AttrNumber) 2, "sess_id", INT4OID, -1, 0); + TupleDescInitEntry(tupdesc, (AttrNumber) 3, "path", TEXTOID, -1, 0); + TupleDescInitEntry(tupdesc, (AttrNumber) 4, "content", INT2OID, -1, 0); + TupleDescInitEntry(tupdesc, (AttrNumber) 5, "size", INT8OID, -1, 0); + + funcctx->tuple_desc = BlessTupleDesc(tupdesc); + + if (head->node.num == 0) + { + MemoryContextSwitchTo(oldcontext); + SRF_RETURN_DONE(funcctx); + } + + LWLockAcquire(&head->lock, LW_SHARED); + + /* Count files of temp tables */ + for (TTSNode *node = &head->node; node != NULL; node = next_node(node)) + files_num += node->num; + + /* Allocate local memory for array of the files data */ + files = palloc(sizeof(*files) * files_num); + + /* Combine arrays from the list nodes into one array */ + funcctx->max_calls = 0; + for (TTSNode *node = &head->node; node != NULL; node = next_node(node)) + { + RelFileNodeBackend *dst = files + funcctx->max_calls; + memcpy(dst, node->files, sizeof(*files) * node->num); + funcctx->max_calls += node->num; + } + + LWLockRelease(&head->lock); + + funcctx->user_fctx = files; + MemoryContextSwitchTo(oldcontext); + } + + funcctx = SRF_PERCALL_SETUP(); + + if (funcctx->call_cntr >= funcctx->max_calls) + SRF_RETURN_DONE(funcctx); + + if (beStatuses == NULL) + { + bool found; + Size size = mul_size(sizeof(PgBackendStatus), MaxBackends); + beStatuses = ShmemInitStruct("Backend Status Array", size, &found); + if (!found) + ereport(ERROR, (errmsg("Backend Status Array is not found"))); + } + + file = ((RelFileNodeBackend *) funcctx->user_fctx) + funcctx->call_cntr; + + beStatus = &beStatuses[file->backend - 1]; + values[0] = ObjectIdGetDatum(beStatus->st_userid); + values[1] = Int32GetDatum(beStatus->st_session_id); + path = relpathbackend(file->node, TempRelBackendId, MAIN_FORKNUM); + values[2] = CStringGetTextDatum(path); + values[3] = Int16GetDatum(GpIdentity.segindex); + sep = strrchr(path, '/'); + Assert(sep != NULL); + *sep = '\0'; + values[4] = Int64GetDatum(tts_get_file_size(path, sep + 1)); + + tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls); + + SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple)); +} + +void +_PG_init(void) +{ + if (!process_shared_preload_libraries_in_progress) + { + ereport(ERROR, + (errmsg("temp_tables_stat is not in shared_preload_libraries"))); + } + + if (IS_QUERY_DISPATCHER()) + return; + + RequestAddinShmemSpace(sizeof(TTSHeadNode)); + RequestAddinLWLocks(1); + + prev_file_create_hook = file_create_hook; + file_create_hook = tts_file_create_hook; + + prev_file_unlink_hook = file_unlink_hook; + file_unlink_hook = tts_file_unlink_hook; + + prev_shmem_startup_hook = shmem_startup_hook; + shmem_startup_hook = tts_shmem_startup; +} + +void +_PG_fini(void) +{ + if (IS_QUERY_DISPATCHER()) + return; + + file_create_hook = prev_file_create_hook; + file_unlink_hook = prev_file_unlink_hook; + shmem_startup_hook = prev_shmem_startup_hook; +} diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat.control b/gpcontrib/temp_tables_stat/temp_tables_stat.control new file mode 100644 index 00000000000..bbd82c90ed9 --- /dev/null +++ b/gpcontrib/temp_tables_stat/temp_tables_stat.control @@ -0,0 +1,5 @@ +# temp_tables_stat extension +comment = 'Collect and show statictics on temporary tables' +default_version = '0.1' +module_pathname = '$libdir/temp_tables_stat' +relocatable = true diff --git a/src/test/isolation2/Makefile b/src/test/isolation2/Makefile index 87c54fd4307..9a2d40b4b0e 100644 --- a/src/test/isolation2/Makefile +++ b/src/test/isolation2/Makefile @@ -76,6 +76,8 @@ installcheck: install installcheck-parallel-retrieve-cursor installcheck-ic-tcp installcheck-mdb: install ./pg_isolation2_regress $(EXTRA_REGRESS_OPTS) --init-file=$(top_builddir)/src/test/regress/init_file --init-file=./init_file_isolation2 --psqldir='$(PSQLDIR)' --inputdir=$(srcdir) --schedule=$(srcdir)/isolation2_schedule_mdb +installcheck-tts: install + ./pg_isolation2_regress $(EXTRA_REGRESS_OPTS) --init-file=$(top_builddir)/src/test/regress/init_file --init-file=./init_file_isolation2 --psqldir='$(PSQLDIR)' --inputdir=$(srcdir) temp_tables_stat installcheck-resgroup: install ./pg_isolation2_regress $(EXTRA_REGRESS_OPTS) --init-file=$(top_builddir)/src/test/regress/init_file --init-file=./init_file_resgroup --psqldir='$(PSQLDIR)' --inputdir=$(srcdir) --dbname=isolation2resgrouptest --schedule=$(srcdir)/isolation2_resgroup_schedule diff --git a/src/test/isolation2/expected/temp_tables_stat.out b/src/test/isolation2/expected/temp_tables_stat.out new file mode 100644 index 00000000000..3b40f32f5d6 --- /dev/null +++ b/src/test/isolation2/expected/temp_tables_stat.out @@ -0,0 +1,1380 @@ +-- start_ignore +0: ! gpconfig -c shared_preload_libraries -v 'temp_tables_stat'; +20251120:10:17:27:025975 gpconfig:sokolov43a-yu-lin:sokolov43a-yu-[INFO]:-completed successfully with parameters '-c shared_preload_libraries -v temp_tables_stat' + +0: ! gpstop -raiq; + + +1: CREATE EXTENSION IF NOT EXISTS temp_tables_stat; +CREATE +-- end_ignore + +-- No tables, the files list is empty +1: SELECT * FROM tts_get_seg_files(); + user_id | sess_id | path | content | size +---------+---------+------+---------+------ +(0 rows) + +-- +-- Ordinary heap tables + +-- We can see tables created in the current session +1: CREATE TEMP TABLE t1(i INT) DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; + user_id_ok | sess_id_ok | content | size +------------+------------+---------+------ + t | t | 0 | 0 + t | t | 2 | 0 + t | t | 1 | 0 +(3 rows) +1: CREATE TEMP TABLE t2(i INT) DISTRIBUTED BY (i); +CREATE +1: CREATE TEMP TABLE t3(i INT) DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; + user_id_ok | sess_id_ok | content | size +------------+------------+---------+------ + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 +(9 rows) + +-- We can see tables created in other sessions +2: CREATE TEMP TABLE t1(i INT) DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------ + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | f | 0 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | f | 1 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | f | 2 | 0 +(12 rows) +2: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------ + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | t | 1 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | t | 0 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | t | 2 | 0 +(12 rows) +3: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------ + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 +(12 rows) + +-- Dropped tables are removed from the list in all sessions +1: DROP TABLE t2; +DROP +1: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 9 +(1 row) +2: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 9 +(1 row) +3: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 9 +(1 row) +2: DROP TABLE t1; +DROP +1: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 6 +(1 row) +2: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 6 +(1 row) +3: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 6 +(1 row) +1q: ... +2q: ... +3q: ... + +-- +-- Heap tables, on commit drop + +-- We can see tables created in the current session +1: BEGIN; +BEGIN +1: CREATE TEMP TABLE t1(i INT) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; + user_id_ok | sess_id_ok | content | size +------------+------------+---------+------ + t | t | 0 | 0 + t | t | 2 | 0 + t | t | 1 | 0 +(3 rows) +1: CREATE TEMP TABLE t2(i INT) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: CREATE TEMP TABLE t3(i INT) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; + user_id_ok | sess_id_ok | content | size +------------+------------+---------+------ + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 +(9 rows) + +-- We can see tables created in other sessions +2: BEGIN; +BEGIN +2: CREATE TEMP TABLE t1(i INT) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------ + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | f | 1 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | f | 0 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | f | 2 | 0 +(12 rows) +2: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------ + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | t | 1 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | t | 2 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | t | 0 | 0 +(12 rows) +3: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------ + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 +(12 rows) + +-- Dropped tables are removed from the list in all sessions +1: ROLLBACK; +ROLLBACK +1: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 3 +(1 row) +2: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 3 +(1 row) +3: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 3 +(1 row) +2: COMMIT; +COMMIT +1: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 0 +(1 row) +2: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 0 +(1 row) +3: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 0 +(1 row) +1q: ... +2q: ... +3q: ... + +-- +-- Ordinary AO tables +-- 4 files per AO table: data file, pg_aoseg, pg_aovisimap, pg_aovisimap_index + +-- We can see tables created in the current session +1: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; + user_id_ok | sess_id_ok | content | size +------------+------------+---------+------- + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 +(12 rows) +1: CREATE TEMP TABLE t2(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); +CREATE +1: CREATE TEMP TABLE t3(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; + user_id_ok | sess_id_ok | content | size +------------+------------+---------+------- + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 +(36 rows) + +-- We can see tables created in other sessions +2: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 +(48 rows) +2: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 +(48 rows) +3: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 +(48 rows) + +-- Dropped tables are removed from the list in all sessions +1: DROP TABLE t2; +DROP +1: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 36 +(1 row) +2: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 36 +(1 row) +3: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 36 +(1 row) +2: DROP TABLE t1; +DROP +1: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 24 +(1 row) +2: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 24 +(1 row) +3: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 24 +(1 row) +1q: ... +2q: ... +3q: ... + +-- +-- AO tables, on commit drop + +-- We can see tables created in the current session +1: BEGIN; +BEGIN +1: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; + user_id_ok | sess_id_ok | content | size +------------+------------+---------+------- + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 +(12 rows) +1: CREATE TEMP TABLE t2(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: CREATE TEMP TABLE t3(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; + user_id_ok | sess_id_ok | content | size +------------+------------+---------+------- + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 +(36 rows) + +-- We can see tables created in other sessions +2: BEGIN; +BEGIN +2: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 +(48 rows) +2: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 +(48 rows) +3: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 +(48 rows) + +-- Dropped tables are removed from the list in all sessions +1: ROLLBACK; +ROLLBACK +1: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 12 +(1 row) +2: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 12 +(1 row) +3: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 12 +(1 row) +2: COMMIT; +COMMIT +1: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 0 +(1 row) +2: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 0 +(1 row) +3: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 0 +(1 row) +1q: ... +2q: ... +3q: ... + +-- +-- Ordinary AOCO tables +-- 4 files per AOCO table: data file, pg_aocsseg, pg_aovisimap, pg_aovisimap_index + +-- We can see tables created in the current session +1: CREATE TEMP TABLE t1(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; + user_id_ok | sess_id_ok | content | size +------------+------------+---------+------- + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 +(12 rows) +1: CREATE TEMP TABLE t2(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) DISTRIBUTED BY (i); +CREATE +1: CREATE TEMP TABLE t3(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; + user_id_ok | sess_id_ok | content | size +------------+------------+---------+------- + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 +(36 rows) + +-- We can see tables created in other sessions +2: CREATE TEMP TABLE t1(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 +(48 rows) +2: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 +(48 rows) +3: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 +(48 rows) + +-- Dropped tables are removed from the list in all sessions +1: DROP TABLE t2; +DROP +1: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 36 +(1 row) +2: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 36 +(1 row) +3: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 36 +(1 row) +2: DROP TABLE t1; +DROP +1: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 24 +(1 row) +2: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 24 +(1 row) +3: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 24 +(1 row) +1q: ... +2q: ... +3q: ... + + +-- +-- AO tables, on commit drop + +-- We can see tables created in the current session +1: BEGIN; +BEGIN +1: CREATE TEMP TABLE t1(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; + user_id_ok | sess_id_ok | content | size +------------+------------+---------+------- + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 +(12 rows) +1: CREATE TEMP TABLE t2(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: CREATE TEMP TABLE t3(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; + user_id_ok | sess_id_ok | content | size +------------+------------+---------+------- + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 +(36 rows) + +-- We can see tables created in other sessions +2: BEGIN; +BEGIN +2: CREATE TEMP TABLE t1(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 +(48 rows) +2: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 +(48 rows) +3: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 +(48 rows) + +-- Dropped tables are removed from the list in all sessions +1: ROLLBACK; +ROLLBACK +1: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 12 +(1 row) +2: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 12 +(1 row) +3: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 12 +(1 row) +2: COMMIT; +COMMIT +1: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 0 +(1 row) +2: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 0 +(1 row) +3: SELECT COUNT(*) FROM tts_get_seg_files(); + count +------- + 0 +(1 row) +1q: ... +2q: ... +3q: ... + +-- +-- Check that files size calculation takes into account all the forks +CREATE TEMP TABLE t1 WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) AS SELECT i, i j FROM generate_series(1, 100) i DISTRIBUTED BY (i); +CREATE 100 +-- t1 consists of two colums. Both column files are taken into account +SELECT content, size FROM tts_get_seg_files(); + content | size +---------+------- + 0 | 384 + 0 | 32768 + 0 | 0 + 0 | 32768 + 1 | 384 + 1 | 32768 + 1 | 0 + 1 | 32768 + 2 | 288 + 2 | 32768 + 2 | 0 + 2 | 32768 +(12 rows) +-- Vaccum adds FSM and VM +VACUUM t1; +VACUUM +SELECT content, size FROM tts_get_seg_files(); + content | size +---------+-------- + 0 | 384 + 0 | 163840 + 0 | 0 + 0 | 32768 + 1 | 384 + 1 | 163840 + 1 | 0 + 1 | 32768 + 2 | 288 + 2 | 163840 + 2 | 0 + 2 | 32768 +(12 rows) diff --git a/src/test/isolation2/sql/temp_tables_stat.sql b/src/test/isolation2/sql/temp_tables_stat.sql new file mode 100644 index 00000000000..d6ade233cdc --- /dev/null +++ b/src/test/isolation2/sql/temp_tables_stat.sql @@ -0,0 +1,464 @@ +-- start_ignore +0: ! gpconfig -c shared_preload_libraries -v 'temp_tables_stat'; +0: ! gpstop -raiq; + +1: CREATE EXTENSION IF NOT EXISTS temp_tables_stat; +-- end_ignore + +-- No tables, the files list is empty +1: SELECT * FROM tts_get_seg_files(); + +-- +-- Ordinary heap tables + +-- We can see tables created in the current session +1: CREATE TEMP TABLE t1(i INT) DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') sess_id_ok, + content, + size + FROM tts_get_seg_files() f; +1: CREATE TEMP TABLE t2(i INT) DISTRIBUTED BY (i); +1: CREATE TEMP TABLE t3(i INT) DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') sess_id_ok, + content, + size + FROM tts_get_seg_files() f; + +-- We can see tables created in other sessions +2: CREATE TEMP TABLE t1(i INT) DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; +2: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; +3: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; + +-- Dropped tables are removed from the list in all sessions +1: DROP TABLE t2; +1: SELECT COUNT(*) FROM tts_get_seg_files(); +2: SELECT COUNT(*) FROM tts_get_seg_files(); +3: SELECT COUNT(*) FROM tts_get_seg_files(); +2: DROP TABLE t1; +1: SELECT COUNT(*) FROM tts_get_seg_files(); +2: SELECT COUNT(*) FROM tts_get_seg_files(); +3: SELECT COUNT(*) FROM tts_get_seg_files(); +1q: +2q: +3q: + +-- +-- Heap tables, on commit drop + +-- We can see tables created in the current session +1: BEGIN; +1: CREATE TEMP TABLE t1(i INT) ON COMMIT DROP DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') sess_id_ok, + content, + size + FROM tts_get_seg_files() f; +1: CREATE TEMP TABLE t2(i INT) ON COMMIT DROP DISTRIBUTED BY (i); +1: CREATE TEMP TABLE t3(i INT) ON COMMIT DROP DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') sess_id_ok, + content, + size + FROM tts_get_seg_files() f; + +-- We can see tables created in other sessions +2: BEGIN; +2: CREATE TEMP TABLE t1(i INT) ON COMMIT DROP DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; +2: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; +3: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; + +-- Dropped tables are removed from the list in all sessions +1: ROLLBACK; +1: SELECT COUNT(*) FROM tts_get_seg_files(); +2: SELECT COUNT(*) FROM tts_get_seg_files(); +3: SELECT COUNT(*) FROM tts_get_seg_files(); +2: COMMIT; +1: SELECT COUNT(*) FROM tts_get_seg_files(); +2: SELECT COUNT(*) FROM tts_get_seg_files(); +3: SELECT COUNT(*) FROM tts_get_seg_files(); +1q: +2q: +3q: + +-- +-- Ordinary AO tables +-- 4 files per AO table: data file, pg_aoseg, pg_aovisimap, pg_aovisimap_index + +-- We can see tables created in the current session +1: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') sess_id_ok, + content, + size + FROM tts_get_seg_files() f; +1: CREATE TEMP TABLE t2(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); +1: CREATE TEMP TABLE t3(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') sess_id_ok, + content, + size + FROM tts_get_seg_files() f; + +-- We can see tables created in other sessions +2: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; +2: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; +3: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; + +-- Dropped tables are removed from the list in all sessions +1: DROP TABLE t2; +1: SELECT COUNT(*) FROM tts_get_seg_files(); +2: SELECT COUNT(*) FROM tts_get_seg_files(); +3: SELECT COUNT(*) FROM tts_get_seg_files(); +2: DROP TABLE t1; +1: SELECT COUNT(*) FROM tts_get_seg_files(); +2: SELECT COUNT(*) FROM tts_get_seg_files(); +3: SELECT COUNT(*) FROM tts_get_seg_files(); +1q: +2q: +3q: + +-- +-- AO tables, on commit drop + +-- We can see tables created in the current session +1: BEGIN; +1: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') sess_id_ok, + content, + size + FROM tts_get_seg_files() f; +1: CREATE TEMP TABLE t2(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); +1: CREATE TEMP TABLE t3(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') sess_id_ok, + content, + size + FROM tts_get_seg_files() f; + +-- We can see tables created in other sessions +2: BEGIN; +2: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; +2: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; +3: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; + +-- Dropped tables are removed from the list in all sessions +1: ROLLBACK; +1: SELECT COUNT(*) FROM tts_get_seg_files(); +2: SELECT COUNT(*) FROM tts_get_seg_files(); +3: SELECT COUNT(*) FROM tts_get_seg_files(); +2: COMMIT; +1: SELECT COUNT(*) FROM tts_get_seg_files(); +2: SELECT COUNT(*) FROM tts_get_seg_files(); +3: SELECT COUNT(*) FROM tts_get_seg_files(); +1q: +2q: +3q: + +-- +-- Ordinary AOCO tables +-- 4 files per AOCO table: data file, pg_aocsseg, pg_aovisimap, pg_aovisimap_index + +-- We can see tables created in the current session +1: CREATE TEMP TABLE t1(i INT, j INT) + WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) + DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') sess_id_ok, + content, + size + FROM tts_get_seg_files() f; +1: CREATE TEMP TABLE t2(i INT, j INT) + WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) + DISTRIBUTED BY (i); +1: CREATE TEMP TABLE t3(i INT, j INT) + WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) + DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') sess_id_ok, + content, + size + FROM tts_get_seg_files() f; + +-- We can see tables created in other sessions +2: CREATE TEMP TABLE t1(i INT, j INT) + WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) + DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; +2: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; +3: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; + +-- Dropped tables are removed from the list in all sessions +1: DROP TABLE t2; +1: SELECT COUNT(*) FROM tts_get_seg_files(); +2: SELECT COUNT(*) FROM tts_get_seg_files(); +3: SELECT COUNT(*) FROM tts_get_seg_files(); +2: DROP TABLE t1; +1: SELECT COUNT(*) FROM tts_get_seg_files(); +2: SELECT COUNT(*) FROM tts_get_seg_files(); +3: SELECT COUNT(*) FROM tts_get_seg_files(); +1q: +2q: +3q: + + +-- +-- AO tables, on commit drop + +-- We can see tables created in the current session +1: BEGIN; +1: CREATE TEMP TABLE t1(i INT, j INT) + WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) + ON COMMIT DROP + DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') sess_id_ok, + content, + size + FROM tts_get_seg_files() f; +1: CREATE TEMP TABLE t2(i INT, j INT) + WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) + ON COMMIT DROP + DISTRIBUTED BY (i); +1: CREATE TEMP TABLE t3(i INT, j INT) + WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) + ON COMMIT DROP + DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') sess_id_ok, + content, + size + FROM tts_get_seg_files() f; + +-- We can see tables created in other sessions +2: BEGIN; +2: CREATE TEMP TABLE t1(i INT, j INT) + WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) + ON COMMIT DROP + DISTRIBUTED BY (i); +1: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; +2: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; +3: SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; + +-- Dropped tables are removed from the list in all sessions +1: ROLLBACK; +1: SELECT COUNT(*) FROM tts_get_seg_files(); +2: SELECT COUNT(*) FROM tts_get_seg_files(); +3: SELECT COUNT(*) FROM tts_get_seg_files(); +2: COMMIT; +1: SELECT COUNT(*) FROM tts_get_seg_files(); +2: SELECT COUNT(*) FROM tts_get_seg_files(); +3: SELECT COUNT(*) FROM tts_get_seg_files(); +1q: +2q: +3q: + +-- +-- Check that files size calculation takes into account all the forks +CREATE TEMP TABLE t1 + WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) + AS SELECT i, i j FROM generate_series(1, 100) i + DISTRIBUTED BY (i); +-- t1 consists of two colums. Both column files are taken into account +SELECT content, size FROM tts_get_seg_files(); +-- Vaccum adds FSM and VM +VACUUM t1; +SELECT content, size FROM tts_get_seg_files(); From 381b5f653c33baa51173b55a0cf77faf0ed37de8 Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Thu, 20 Nov 2025 11:12:46 +0300 Subject: [PATCH 02/14] Remove redundant lines --- src/test/isolation2/expected/temp_tables_stat.out | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/test/isolation2/expected/temp_tables_stat.out b/src/test/isolation2/expected/temp_tables_stat.out index 3b40f32f5d6..5dfe4c8fd7f 100644 --- a/src/test/isolation2/expected/temp_tables_stat.out +++ b/src/test/isolation2/expected/temp_tables_stat.out @@ -1,13 +1,3 @@ --- start_ignore -0: ! gpconfig -c shared_preload_libraries -v 'temp_tables_stat'; -20251120:10:17:27:025975 gpconfig:sokolov43a-yu-lin:sokolov43a-yu-[INFO]:-completed successfully with parameters '-c shared_preload_libraries -v temp_tables_stat' - -0: ! gpstop -raiq; - - -1: CREATE EXTENSION IF NOT EXISTS temp_tables_stat; -CREATE --- end_ignore -- No tables, the files list is empty 1: SELECT * FROM tts_get_seg_files(); From c6ca9b982387c0481811ae27e5464ead88e92209 Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Fri, 21 Nov 2025 11:07:44 +0300 Subject: [PATCH 03/14] Fix typo --- gpcontrib/temp_tables_stat/Makefile | 2 +- gpcontrib/temp_tables_stat/temp_tables_stat.control | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gpcontrib/temp_tables_stat/Makefile b/gpcontrib/temp_tables_stat/Makefile index df1644727cf..2b198777c95 100644 --- a/gpcontrib/temp_tables_stat/Makefile +++ b/gpcontrib/temp_tables_stat/Makefile @@ -4,7 +4,7 @@ MODULE_big = temp_tables_stat OBJS = $(MODULE_big).o $(WIN32RES) EXTENSION = $(MODULE_big) -PGFILEDESC = "Collect and show statictics on temporary tables" +PGFILEDESC = "Collect and show statistics on temporary tables" DATA = $(MODULE_big)--0.1.sql diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat.control b/gpcontrib/temp_tables_stat/temp_tables_stat.control index bbd82c90ed9..b08ce3480f1 100644 --- a/gpcontrib/temp_tables_stat/temp_tables_stat.control +++ b/gpcontrib/temp_tables_stat/temp_tables_stat.control @@ -1,5 +1,5 @@ # temp_tables_stat extension -comment = 'Collect and show statictics on temporary tables' +comment = 'Collect and show statistics on temporary tables' default_version = '0.1' module_pathname = '$libdir/temp_tables_stat' relocatable = true From e4cccb49fab9f061637228fb5e63eb4ab0f4b3be Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Fri, 21 Nov 2025 11:30:16 +0300 Subject: [PATCH 04/14] Add check for NULL --- gpcontrib/temp_tables_stat/temp_tables_stat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat.c b/gpcontrib/temp_tables_stat/temp_tables_stat.c index 7a16da1015f..a86f0cf47b6 100644 --- a/gpcontrib/temp_tables_stat/temp_tables_stat.c +++ b/gpcontrib/temp_tables_stat/temp_tables_stat.c @@ -74,7 +74,7 @@ tts_file_create_hook(RelFileNodeBackend rnode) if (prev_file_create_hook) (*prev_file_create_hook)(rnode); - if (!RelFileNodeBackendIsTemp(rnode)) + if (!RelFileNodeBackendIsTemp(rnode) || head == NULL) return; rnode.backend = MyBackendId; @@ -116,7 +116,7 @@ tts_file_unlink_hook(RelFileNodeBackend rnode) if (prev_file_unlink_hook) (*prev_file_unlink_hook)(rnode); - if (!RelFileNodeBackendIsTemp(rnode)) + if (!RelFileNodeBackendIsTemp(rnode) || head == NULL) return; rnode.backend = MyBackendId; From 47ca73d35367eb8d48c0b363d0c823a3134b8e9c Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Sat, 22 Nov 2025 21:51:09 +0300 Subject: [PATCH 05/14] Fixes after Sonar checks --- gpcontrib/temp_tables_stat/temp_tables_stat.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat.c b/gpcontrib/temp_tables_stat/temp_tables_stat.c index a86f0cf47b6..86a4d3b0515 100644 --- a/gpcontrib/temp_tables_stat/temp_tables_stat.c +++ b/gpcontrib/temp_tables_stat/temp_tables_stat.c @@ -134,7 +134,8 @@ tts_file_unlink_hook(RelFileNodeBackend rnode) if (RelFileNodeBackendEquals(rnode, node->files[i])) { /* Find the last node */ - TTSNode *last_node = node, *last_prev_node = prev_node; + TTSNode *last_node = node; + TTSNode *last_prev_node = prev_node; while (last_node->next != DSM_HANDLE_INVALID) { last_prev_node = last_node; @@ -233,8 +234,8 @@ tts_get_seg_files(PG_FUNCTION_ARGS) enum { NATTR = 5 }; FuncCallContext *funcctx; - PgBackendStatus *beStatus; - RelFileNodeBackend *file; + const PgBackendStatus *beStatus; + const RelFileNodeBackend *file; char *sep; char *path; HeapTuple tuple; @@ -271,7 +272,7 @@ tts_get_seg_files(PG_FUNCTION_ARGS) LWLockAcquire(&head->lock, LW_SHARED); /* Count files of temp tables */ - for (TTSNode *node = &head->node; node != NULL; node = next_node(node)) + for (const TTSNode *node = &head->node; node != NULL; node = next_node(node)) files_num += node->num; /* Allocate local memory for array of the files data */ @@ -279,7 +280,7 @@ tts_get_seg_files(PG_FUNCTION_ARGS) /* Combine arrays from the list nodes into one array */ funcctx->max_calls = 0; - for (TTSNode *node = &head->node; node != NULL; node = next_node(node)) + for (const TTSNode *node = &head->node; node != NULL; node = next_node(node)) { RelFileNodeBackend *dst = files + funcctx->max_calls; memcpy(dst, node->files, sizeof(*files) * node->num); @@ -318,6 +319,7 @@ tts_get_seg_files(PG_FUNCTION_ARGS) Assert(sep != NULL); *sep = '\0'; values[4] = Int64GetDatum(tts_get_file_size(path, sep + 1)); + pfree(path); tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls); From e2ce596a3c679b3ab93dc14a71634ed31b9369b3 Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Sat, 22 Nov 2025 22:14:12 +0300 Subject: [PATCH 06/14] Fixes after Sonar checks --- gpcontrib/temp_tables_stat/temp_tables_stat.c | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat.c b/gpcontrib/temp_tables_stat/temp_tables_stat.c index 86a4d3b0515..52f7150c8fb 100644 --- a/gpcontrib/temp_tables_stat/temp_tables_stat.c +++ b/gpcontrib/temp_tables_stat/temp_tables_stat.c @@ -109,6 +109,37 @@ tts_file_create_hook(RelFileNodeBackend rnode) LWLockRelease(&head->lock); } +static void +delete_from_ttsnode(TTSNode *node, int index, TTSNode *prev_node) +{ + /* Find the last node */ + TTSNode *last_node = node; + TTSNode *last_prev_node = prev_node; + + while (last_node->next != DSM_HANDLE_INVALID) + { + last_prev_node = last_node; + last_node = next_node(last_node); + } + + /* replace the deleted element with the last one */ + node->files[index] = last_node->files[last_node->num - 1]; + + if (last_node->num > 1) + last_node->num--; + else if (last_node == &head->node) + head->node.num = 0; + else + { + /* + * last_prev_node != NULL because last_node is not head. + * next_node() has been called, so the mapping exists. + */ + dsm_detach(dsm_find_mapping(last_prev_node->next)); + last_prev_node->next = DSM_HANDLE_INVALID; + } +} + /* This function is called once for all forks. Delete file info from the list */ static void tts_file_unlink_hook(RelFileNodeBackend rnode) @@ -122,10 +153,7 @@ tts_file_unlink_hook(RelFileNodeBackend rnode) rnode.backend = MyBackendId; LWLockAcquire(&head->lock, LW_EXCLUSIVE); - /* - * Find rnode in the list of arrays, replace rnode with the last element, - * decrement array length. - */ + /* Find rnode in the list of arrays and delete it from the list node */ for (TTSNode *node = &head->node, *prev_node = NULL; node != NULL; prev_node = node, node = next_node(node)) @@ -133,31 +161,7 @@ tts_file_unlink_hook(RelFileNodeBackend rnode) for (int i = 0; i < node->num; i++) if (RelFileNodeBackendEquals(rnode, node->files[i])) { - /* Find the last node */ - TTSNode *last_node = node; - TTSNode *last_prev_node = prev_node; - while (last_node->next != DSM_HANDLE_INVALID) - { - last_prev_node = last_node; - last_node = next_node(last_node); - } - - node->files[i] = last_node->files[last_node->num - 1]; - - if (last_node->num > 1) - last_node->num--; - else if (last_node == &head->node) - head->node.num = 0; - else - { - /* - * last_prev_node != NULL because last_node is not head. - * next_node() has been called, so the mapping exists. - */ - dsm_detach(dsm_find_mapping(last_prev_node->next)); - last_prev_node->next = DSM_HANDLE_INVALID; - } - + delete_from_ttsnode(node, i, prev_node); goto lExit; } } From a133b59ff7b7e6a64c1e274bd81c59cac72e5ba3 Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Sat, 22 Nov 2025 22:41:48 +0300 Subject: [PATCH 07/14] Add the get_files function to simplify the code --- gpcontrib/temp_tables_stat/temp_tables_stat.c | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat.c b/gpcontrib/temp_tables_stat/temp_tables_stat.c index 52f7150c8fb..f31a3cd6448 100644 --- a/gpcontrib/temp_tables_stat/temp_tables_stat.c +++ b/gpcontrib/temp_tables_stat/temp_tables_stat.c @@ -230,6 +230,37 @@ tts_get_file_size(const char *dirname, const char *fn_start) return dirsize; } +/* Copy the files info from the list to local memory */ +static RelFileNodeBackend * +get_files(uint32 *files_num) +{ + RelFileNodeBackend *files; + + *files_num = 0; + + LWLockAcquire(&head->lock, LW_SHARED); + + /* Count files of temp tables */ + for (const TTSNode *node = &head->node; node != NULL; node = next_node(node)) + *files_num += node->num; + + /* Allocate local memory for array of the files data */ + files = palloc(sizeof(*files) * (*files_num)); + + /* Combine arrays from the list nodes into one array */ + *files_num = 0; + for (const TTSNode *node = &head->node; node != NULL; node = next_node(node)) + { + RelFileNodeBackend *dst = files + (*files_num); + memcpy(dst, node->files, sizeof(*files) * node->num); + *files_num += node->num; + } + + LWLockRelease(&head->lock); + + return files; +} + /* Get temp tables files list on segments */ PG_FUNCTION_INFO_V1(tts_get_seg_files); Datum @@ -251,8 +282,6 @@ tts_get_seg_files(PG_FUNCTION_ARGS) { MemoryContext oldcontext; TupleDesc tupdesc; - RelFileNodeBackend *files; - int files_num = 0; funcctx = SRF_FIRSTCALL_INIT(); @@ -273,27 +302,7 @@ tts_get_seg_files(PG_FUNCTION_ARGS) SRF_RETURN_DONE(funcctx); } - LWLockAcquire(&head->lock, LW_SHARED); - - /* Count files of temp tables */ - for (const TTSNode *node = &head->node; node != NULL; node = next_node(node)) - files_num += node->num; - - /* Allocate local memory for array of the files data */ - files = palloc(sizeof(*files) * files_num); - - /* Combine arrays from the list nodes into one array */ - funcctx->max_calls = 0; - for (const TTSNode *node = &head->node; node != NULL; node = next_node(node)) - { - RelFileNodeBackend *dst = files + funcctx->max_calls; - memcpy(dst, node->files, sizeof(*files) * node->num); - funcctx->max_calls += node->num; - } - - LWLockRelease(&head->lock); - - funcctx->user_fctx = files; + funcctx->user_fctx = get_files(&funcctx->max_calls); MemoryContextSwitchTo(oldcontext); } From 83cc3e6deb215b40e60ea6df7daef674e19685bf Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Sat, 22 Nov 2025 22:57:07 +0300 Subject: [PATCH 08/14] Fix tests --- src/test/isolation2/expected/temp_tables_stat.out | 6 ++++++ src/test/isolation2/sql/temp_tables_stat.sql | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/test/isolation2/expected/temp_tables_stat.out b/src/test/isolation2/expected/temp_tables_stat.out index 5dfe4c8fd7f..6c42598b203 100644 --- a/src/test/isolation2/expected/temp_tables_stat.out +++ b/src/test/isolation2/expected/temp_tables_stat.out @@ -1368,3 +1368,9 @@ SELECT content, size FROM tts_get_seg_files(); 2 | 0 2 | 32768 (12 rows) + +-- +-- Cleanup +DROP EXTENSION temp_tables_stat; +DROP + diff --git a/src/test/isolation2/sql/temp_tables_stat.sql b/src/test/isolation2/sql/temp_tables_stat.sql index d6ade233cdc..d801ac4607e 100644 --- a/src/test/isolation2/sql/temp_tables_stat.sql +++ b/src/test/isolation2/sql/temp_tables_stat.sql @@ -462,3 +462,12 @@ SELECT content, size FROM tts_get_seg_files(); -- Vaccum adds FSM and VM VACUUM t1; SELECT content, size FROM tts_get_seg_files(); + +-- +-- Cleanup +DROP EXTENSION temp_tables_stat; + +-- start_ignore +! gpconfig -r shared_preload_libraries; +! gpstop -raiq; +-- end_ignore From 53fc95ad516e17194c2809c440973e1ed4f64e5a Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Sun, 23 Nov 2025 12:42:29 +0300 Subject: [PATCH 09/14] Fixes after Sonar checks --- gpcontrib/temp_tables_stat/temp_tables_stat.c | 2 +- .../isolation2/expected/temp_tables_stat.out | 935 +++++++++--------- src/test/isolation2/sql/temp_tables_stat.sql | 318 +----- 3 files changed, 528 insertions(+), 727 deletions(-) diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat.c b/gpcontrib/temp_tables_stat/temp_tables_stat.c index f31a3cd6448..9a408f7c29a 100644 --- a/gpcontrib/temp_tables_stat/temp_tables_stat.c +++ b/gpcontrib/temp_tables_stat/temp_tables_stat.c @@ -276,7 +276,7 @@ tts_get_seg_files(PG_FUNCTION_ARGS) HeapTuple tuple; Datum values[NATTR] = {0}; bool nulls [NATTR] = {0}; - static PgBackendStatus *beStatuses = NULL; + static const PgBackendStatus *beStatuses = NULL; if (SRF_IS_FIRSTCALL()) { diff --git a/src/test/isolation2/expected/temp_tables_stat.out b/src/test/isolation2/expected/temp_tables_stat.out index 6c42598b203..ef7acc9e616 100644 --- a/src/test/isolation2/expected/temp_tables_stat.out +++ b/src/test/isolation2/expected/temp_tables_stat.out @@ -1,3 +1,16 @@ +-- start_ignore +0: ! gpconfig -c shared_preload_libraries -v 'temp_tables_stat'; +20251123:12:36:14:039354 gpconfig:sokolov43a-yu-lin:sokolov43a-yu-[INFO]:-completed successfully with parameters '-c shared_preload_libraries -v temp_tables_stat' + +0: ! gpstop -raiq; + + +1: CREATE EXTENSION IF NOT EXISTS temp_tables_stat; +CREATE +-- end_ignore + +1: CREATE OR REPLACE FUNCTION get_files (OUT user_id_ok bool, OUT cur_sess_id bool, OUT content int2, OUT size int8) RETURNS SETOF record AS $$ SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; /**/ $$ LANGUAGE SQL; +CREATE -- No tables, the files list is empty 1: SELECT * FROM tts_get_seg_files(); @@ -11,41 +24,37 @@ -- We can see tables created in the current session 1: CREATE TEMP TABLE t1(i INT) DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; - user_id_ok | sess_id_ok | content | size -------------+------------+---------+------ - t | t | 0 | 0 - t | t | 2 | 0 - t | t | 1 | 0 +1: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------ + t | t | 0 | 0 + t | t | 1 | 0 + t | t | 2 | 0 (3 rows) 1: CREATE TEMP TABLE t2(i INT) DISTRIBUTED BY (i); CREATE 1: CREATE TEMP TABLE t3(i INT) DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; - user_id_ok | sess_id_ok | content | size -------------+------------+---------+------ - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 +1: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------ + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 (9 rows) -- We can see tables created in other sessions 2: CREATE TEMP TABLE t1(i INT) DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------ - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | f | 0 | 0 t | t | 1 | 0 t | t | 1 | 0 t | t | 1 | 0 @@ -54,24 +63,28 @@ CREATE t | t | 2 | 0 t | t | 2 | 0 t | f | 2 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | f | 0 | 0 (12 rows) -2: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +2: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------ - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | t | 1 | 0 t | f | 0 | 0 t | f | 0 | 0 t | f | 0 | 0 t | t | 0 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | t | 1 | 0 t | f | 2 | 0 t | f | 2 | 0 t | f | 2 | 0 t | t | 2 | 0 (12 rows) -3: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +3: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------ t | f | 0 | 0 @@ -135,29 +148,29 @@ DROP BEGIN 1: CREATE TEMP TABLE t1(i INT) ON COMMIT DROP DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; - user_id_ok | sess_id_ok | content | size -------------+------------+---------+------ - t | t | 0 | 0 - t | t | 2 | 0 - t | t | 1 | 0 +1: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------ + t | t | 1 | 0 + t | t | 2 | 0 + t | t | 0 | 0 (3 rows) 1: CREATE TEMP TABLE t2(i INT) ON COMMIT DROP DISTRIBUTED BY (i); CREATE 1: CREATE TEMP TABLE t3(i INT) ON COMMIT DROP DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; - user_id_ok | sess_id_ok | content | size -------------+------------+---------+------ - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 +1: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------ + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 (9 rows) -- We can see tables created in other sessions @@ -165,9 +178,13 @@ CREATE BEGIN 2: CREATE TEMP TABLE t1(i INT) ON COMMIT DROP DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------ + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | f | 2 | 0 t | t | 1 | 0 t | t | 1 | 0 t | t | 1 | 0 @@ -176,18 +193,10 @@ CREATE t | t | 0 | 0 t | t | 0 | 0 t | f | 0 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | f | 2 | 0 (12 rows) -2: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +2: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------ - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | t | 1 | 0 t | f | 2 | 0 t | f | 2 | 0 t | f | 2 | 0 @@ -196,22 +205,26 @@ CREATE t | f | 0 | 0 t | f | 0 | 0 t | t | 0 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | t | 1 | 0 (12 rows) -3: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +3: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------ - t | f | 0 | 0 - t | f | 0 | 0 - t | f | 0 | 0 - t | f | 0 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 t | f | 1 | 0 t | f | 1 | 0 t | f | 1 | 0 t | f | 1 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 (12 rows) -- Dropped tables are removed from the list in all sessions @@ -260,73 +273,89 @@ COMMIT -- We can see tables created in the current session 1: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; - user_id_ok | sess_id_ok | content | size -------------+------------+---------+------- - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 +1: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 (12 rows) 1: CREATE TEMP TABLE t2(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); CREATE 1: CREATE TEMP TABLE t3(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; - user_id_ok | sess_id_ok | content | size -------------+------------+---------+------- - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 +1: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 (36 rows) -- We can see tables created in other sessions 2: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------- + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 t | t | 0 | 0 t | t | 0 | 0 t | t | 0 | 0 @@ -359,26 +388,26 @@ CREATE t | f | 1 | 0 t | f | 1 | 0 t | f | 1 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 +(48 rows) +2: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- t | f | 2 | 0 t | f | 2 | 0 t | f | 2 | 0 t | f | 2 | 32768 -(48 rows) -2: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; - user_id_ok | cur_sess_id | content | size -------------+-------------+---------+------- + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 t | f | 0 | 0 t | f | 0 | 0 t | f | 0 | 0 @@ -411,42 +440,10 @@ CREATE t | t | 1 | 0 t | t | 1 | 0 t | t | 1 | 32768 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 (48 rows) -3: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +3: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------- - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 t | f | 1 | 0 t | f | 1 | 0 t | f | 1 | 0 @@ -463,6 +460,22 @@ CREATE t | f | 1 | 0 t | f | 1 | 0 t | f | 1 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 t | f | 0 | 0 t | f | 0 | 0 t | f | 0 | 0 @@ -528,73 +541,27 @@ DROP BEGIN 1: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; - user_id_ok | sess_id_ok | content | size -------------+------------+---------+------- - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 +1: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 (12 rows) 1: CREATE TEMP TABLE t2(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); CREATE 1: CREATE TEMP TABLE t3(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; - user_id_ok | sess_id_ok | content | size -------------+------------+---------+------- - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 -(36 rows) - --- We can see tables created in other sessions -2: BEGIN; -BEGIN -2: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); -CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------- t | t | 1 | 0 @@ -609,10 +576,40 @@ CREATE t | t | 1 | 0 t | t | 1 | 0 t | t | 1 | 32768 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 +(36 rows) + +-- We can see tables created in other sessions +2: BEGIN; +BEGIN +2: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); +CREATE +1: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- t | t | 0 | 0 t | t | 0 | 0 t | t | 0 | 0 @@ -629,6 +626,22 @@ CREATE t | f | 0 | 0 t | f | 0 | 0 t | f | 0 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 t | t | 2 | 0 t | t | 2 | 0 t | t | 2 | 0 @@ -646,41 +659,9 @@ CREATE t | f | 2 | 0 t | f | 2 | 32768 (48 rows) -2: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +2: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------- - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 32768 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 32768 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 t | f | 0 | 0 t | f | 0 | 0 t | f | 0 | 0 @@ -697,8 +678,40 @@ CREATE t | t | 0 | 0 t | t | 0 | 0 t | t | 0 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 (48 rows) -3: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +3: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------- t | f | 0 | 0 @@ -797,71 +810,71 @@ COMMIT -- We can see tables created in the current session 1: CREATE TEMP TABLE t1(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; - user_id_ok | sess_id_ok | content | size -------------+------------+---------+------- - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 +1: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 (12 rows) 1: CREATE TEMP TABLE t2(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) DISTRIBUTED BY (i); CREATE 1: CREATE TEMP TABLE t3(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; - user_id_ok | sess_id_ok | content | size -------------+------------+---------+------- - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 +1: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 (36 rows) -- We can see tables created in other sessions 2: CREATE TEMP TABLE t1(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------- t | t | 2 | 0 @@ -913,25 +926,9 @@ CREATE t | f | 1 | 0 t | f | 1 | 32768 (48 rows) -2: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +2: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------- - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 32768 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 32768 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 t | f | 2 | 0 t | f | 2 | 0 t | f | 2 | 0 @@ -964,10 +961,42 @@ CREATE t | t | 0 | 0 t | t | 0 | 0 t | t | 0 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 (48 rows) -3: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +3: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------- + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 0 + t | f | 0 | 32768 t | f | 1 | 0 t | f | 1 | 0 t | f | 1 | 0 @@ -1000,22 +1029,6 @@ CREATE t | f | 2 | 0 t | f | 2 | 0 t | f | 2 | 32768 - t | f | 0 | 0 - t | f | 0 | 0 - t | f | 0 | 0 - t | f | 0 | 32768 - t | f | 0 | 0 - t | f | 0 | 0 - t | f | 0 | 0 - t | f | 0 | 32768 - t | f | 0 | 0 - t | f | 0 | 0 - t | f | 0 | 0 - t | f | 0 | 32768 - t | f | 0 | 0 - t | f | 0 | 0 - t | f | 0 | 0 - t | f | 0 | 32768 (48 rows) -- Dropped tables are removed from the list in all sessions @@ -1066,65 +1079,65 @@ DROP BEGIN 1: CREATE TEMP TABLE t1(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) ON COMMIT DROP DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; - user_id_ok | sess_id_ok | content | size -------------+------------+---------+------- - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 +1: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 (12 rows) 1: CREATE TEMP TABLE t2(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) ON COMMIT DROP DISTRIBUTED BY (i); CREATE 1: CREATE TEMP TABLE t3(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) ON COMMIT DROP DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') sess_id_ok, content, size FROM tts_get_seg_files() f; - user_id_ok | sess_id_ok | content | size -------------+------------+---------+------- - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 0 - t | t | 0 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 0 - t | t | 1 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 +1: SELECT * FROM get_files(); + user_id_ok | cur_sess_id | content | size +------------+-------------+---------+------- + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 0 + t | t | 0 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 0 + t | t | 1 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 (36 rows) -- We can see tables created in other sessions @@ -1132,7 +1145,7 @@ CREATE BEGIN 2: CREATE TEMP TABLE t1(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) ON COMMIT DROP DISTRIBUTED BY (i); CREATE -1: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------- t | t | 2 | 0 @@ -1184,7 +1197,7 @@ CREATE t | f | 1 | 0 t | f | 1 | 32768 (48 rows) -2: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +2: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------- t | f | 1 | 0 @@ -1203,22 +1216,6 @@ CREATE t | t | 1 | 0 t | t | 1 | 0 t | t | 1 | 32768 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 0 - t | f | 2 | 32768 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 0 - t | t | 2 | 32768 t | f | 0 | 0 t | f | 0 | 0 t | f | 0 | 0 @@ -1235,8 +1232,24 @@ CREATE t | t | 0 | 0 t | t | 0 | 0 t | t | 0 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 0 + t | f | 2 | 32768 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 0 + t | t | 2 | 32768 (48 rows) -3: SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; +3: SELECT * FROM get_files(); user_id_ok | cur_sess_id | content | size ------------+-------------+---------+------- t | f | 2 | 0 @@ -1255,22 +1268,6 @@ CREATE t | f | 2 | 0 t | f | 2 | 0 t | f | 2 | 32768 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 32768 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 32768 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 32768 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 0 - t | f | 1 | 32768 t | f | 0 | 0 t | f | 0 | 0 t | f | 0 | 0 @@ -1287,6 +1284,22 @@ CREATE t | f | 0 | 0 t | f | 0 | 0 t | f | 0 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 0 + t | f | 1 | 32768 (48 rows) -- Dropped tables are removed from the list in all sessions @@ -1336,6 +1349,10 @@ CREATE 100 SELECT content, size FROM tts_get_seg_files(); content | size ---------+------- + 2 | 288 + 2 | 32768 + 2 | 0 + 2 | 32768 0 | 384 0 | 32768 0 | 0 @@ -1344,10 +1361,6 @@ SELECT content, size FROM tts_get_seg_files(); 1 | 32768 1 | 0 1 | 32768 - 2 | 288 - 2 | 32768 - 2 | 0 - 2 | 32768 (12 rows) -- Vaccum adds FSM and VM VACUUM t1; @@ -1355,10 +1368,6 @@ VACUUM SELECT content, size FROM tts_get_seg_files(); content | size ---------+-------- - 0 | 384 - 0 | 163840 - 0 | 0 - 0 | 32768 1 | 384 1 | 163840 1 | 0 @@ -1367,10 +1376,24 @@ SELECT content, size FROM tts_get_seg_files(); 2 | 163840 2 | 0 2 | 32768 + 0 | 384 + 0 | 163840 + 0 | 0 + 0 | 32768 (12 rows) -- -- Cleanup +DROP FUNCTION get_files (OUT user_id_ok bool, OUT cur_sess_id bool, OUT content int2, OUT size int8); +DROP + DROP EXTENSION temp_tables_stat; DROP +-- start_ignore +! gpconfig -r shared_preload_libraries; +20251123:12:36:27:042380 gpconfig:sokolov43a-yu-lin:sokolov43a-yu-[INFO]:-completed successfully with parameters '-r shared_preload_libraries' + +! gpstop -raiq; + +-- end_ignore diff --git a/src/test/isolation2/sql/temp_tables_stat.sql b/src/test/isolation2/sql/temp_tables_stat.sql index d801ac4607e..547404f5d09 100644 --- a/src/test/isolation2/sql/temp_tables_stat.sql +++ b/src/test/isolation2/sql/temp_tables_stat.sql @@ -5,6 +5,21 @@ 1: CREATE EXTENSION IF NOT EXISTS temp_tables_stat; -- end_ignore +1: CREATE OR REPLACE FUNCTION get_files +(OUT user_id_ok bool, OUT cur_sess_id bool, OUT content int2, OUT size int8) +RETURNS SETOF record +AS $$ + SELECT (SELECT a.oid = f.user_id + FROM pg_authid a + WHERE a.rolname = current_user) user_id_ok, + (SELECT s.setting::int = f.sess_id + FROM pg_settings s + WHERE name = 'gp_session_id') cur_sess_id, + content, + size + FROM tts_get_seg_files() f; /**/ +$$ LANGUAGE SQL; + -- No tables, the files list is empty 1: SELECT * FROM tts_get_seg_files(); @@ -13,56 +28,16 @@ -- We can see tables created in the current session 1: CREATE TEMP TABLE t1(i INT) DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') sess_id_ok, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); 1: CREATE TEMP TABLE t2(i INT) DISTRIBUTED BY (i); 1: CREATE TEMP TABLE t3(i INT) DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') sess_id_ok, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); -- We can see tables created in other sessions 2: CREATE TEMP TABLE t1(i INT) DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; -2: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; -3: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); +2: SELECT * FROM get_files(); +3: SELECT * FROM get_files(); -- Dropped tables are removed from the list in all sessions 1: DROP TABLE t2; @@ -83,57 +58,17 @@ -- We can see tables created in the current session 1: BEGIN; 1: CREATE TEMP TABLE t1(i INT) ON COMMIT DROP DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') sess_id_ok, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); 1: CREATE TEMP TABLE t2(i INT) ON COMMIT DROP DISTRIBUTED BY (i); 1: CREATE TEMP TABLE t3(i INT) ON COMMIT DROP DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') sess_id_ok, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); -- We can see tables created in other sessions 2: BEGIN; 2: CREATE TEMP TABLE t1(i INT) ON COMMIT DROP DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; -2: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; -3: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); +2: SELECT * FROM get_files(); +3: SELECT * FROM get_files(); -- Dropped tables are removed from the list in all sessions 1: ROLLBACK; @@ -154,56 +89,16 @@ -- We can see tables created in the current session 1: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') sess_id_ok, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); 1: CREATE TEMP TABLE t2(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); 1: CREATE TEMP TABLE t3(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') sess_id_ok, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); -- We can see tables created in other sessions 2: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; -2: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; -3: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); +2: SELECT * FROM get_files(); +3: SELECT * FROM get_files(); -- Dropped tables are removed from the list in all sessions 1: DROP TABLE t2; @@ -224,57 +119,17 @@ -- We can see tables created in the current session 1: BEGIN; 1: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') sess_id_ok, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); 1: CREATE TEMP TABLE t2(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); 1: CREATE TEMP TABLE t3(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') sess_id_ok, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); -- We can see tables created in other sessions 2: BEGIN; 2: CREATE TEMP TABLE t1(i INT) WITH (APPENDOPTIMIZED = TRUE) ON COMMIT DROP DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; -2: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; -3: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); +2: SELECT * FROM get_files(); +3: SELECT * FROM get_files(); -- Dropped tables are removed from the list in all sessions 1: ROLLBACK; @@ -297,62 +152,22 @@ 1: CREATE TEMP TABLE t1(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') sess_id_ok, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); 1: CREATE TEMP TABLE t2(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) DISTRIBUTED BY (i); 1: CREATE TEMP TABLE t3(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') sess_id_ok, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); -- We can see tables created in other sessions 2: CREATE TEMP TABLE t1(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; -2: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; -3: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); +2: SELECT * FROM get_files(); +3: SELECT * FROM get_files(); -- Dropped tables are removed from the list in all sessions 1: DROP TABLE t2; @@ -377,15 +192,7 @@ WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) ON COMMIT DROP DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') sess_id_ok, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); 1: CREATE TEMP TABLE t2(i INT, j INT) WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) ON COMMIT DROP @@ -394,15 +201,7 @@ WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) ON COMMIT DROP DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') sess_id_ok, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); -- We can see tables created in other sessions 2: BEGIN; @@ -410,33 +209,9 @@ WITH (APPENDOPTIMIZED = TRUE, ORIENTATION = COLUMN) ON COMMIT DROP DISTRIBUTED BY (i); -1: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; -2: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; -3: SELECT (SELECT a.oid = f.user_id - FROM pg_authid a - WHERE a.rolname = current_user) user_id_ok, - (SELECT s.setting::int = f.sess_id - FROM pg_settings s - WHERE name = 'gp_session_id') cur_sess_id, - content, - size - FROM tts_get_seg_files() f; +1: SELECT * FROM get_files(); +2: SELECT * FROM get_files(); +3: SELECT * FROM get_files(); -- Dropped tables are removed from the list in all sessions 1: ROLLBACK; @@ -465,6 +240,9 @@ SELECT content, size FROM tts_get_seg_files(); -- -- Cleanup +DROP FUNCTION get_files +(OUT user_id_ok bool, OUT cur_sess_id bool, OUT content int2, OUT size int8); + DROP EXTENSION temp_tables_stat; -- start_ignore From 0384ca208356224112aa39ea636f26505df27c71 Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Sun, 23 Nov 2025 12:54:53 +0300 Subject: [PATCH 10/14] Remove redundant cast --- gpcontrib/temp_tables_stat/temp_tables_stat.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat.c b/gpcontrib/temp_tables_stat/temp_tables_stat.c index 9a408f7c29a..b17f397657a 100644 --- a/gpcontrib/temp_tables_stat/temp_tables_stat.c +++ b/gpcontrib/temp_tables_stat/temp_tables_stat.c @@ -288,11 +288,11 @@ tts_get_seg_files(PG_FUNCTION_ARGS) oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); tupdesc = CreateTemplateTupleDesc(NATTR, false); - TupleDescInitEntry(tupdesc, (AttrNumber) 1, "user_id", OIDOID, -1, 0); - TupleDescInitEntry(tupdesc, (AttrNumber) 2, "sess_id", INT4OID, -1, 0); - TupleDescInitEntry(tupdesc, (AttrNumber) 3, "path", TEXTOID, -1, 0); - TupleDescInitEntry(tupdesc, (AttrNumber) 4, "content", INT2OID, -1, 0); - TupleDescInitEntry(tupdesc, (AttrNumber) 5, "size", INT8OID, -1, 0); + TupleDescInitEntry(tupdesc, 1, "user_id", OIDOID, -1, 0); + TupleDescInitEntry(tupdesc, 2, "sess_id", INT4OID, -1, 0); + TupleDescInitEntry(tupdesc, 3, "path", TEXTOID, -1, 0); + TupleDescInitEntry(tupdesc, 4, "content", INT2OID, -1, 0); + TupleDescInitEntry(tupdesc, 5, "size", INT8OID, -1, 0); funcctx->tuple_desc = BlessTupleDesc(tupdesc); From efbbbfc6cd10d9cafb36d44ca2a20efcc43d2d42 Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Sun, 23 Nov 2025 13:05:20 +0300 Subject: [PATCH 11/14] Fixes after Sonar checks --- src/test/isolation2/expected/temp_tables_stat.out | 2 +- src/test/isolation2/sql/temp_tables_stat.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/isolation2/expected/temp_tables_stat.out b/src/test/isolation2/expected/temp_tables_stat.out index ef7acc9e616..9113b5b03d6 100644 --- a/src/test/isolation2/expected/temp_tables_stat.out +++ b/src/test/isolation2/expected/temp_tables_stat.out @@ -9,7 +9,7 @@ CREATE -- end_ignore -1: CREATE OR REPLACE FUNCTION get_files (OUT user_id_ok bool, OUT cur_sess_id bool, OUT content int2, OUT size int8) RETURNS SETOF record AS $$ SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; /**/ $$ LANGUAGE SQL; +1: CREATE OR REPLACE FUNCTION get_files (OUT user_id_ok bool, OUT cur_sess_id bool, OUT content int2, OUT size int8) RETURNS SETOF record AS $$ SELECT (SELECT a.oid = f.user_id FROM pg_authid a WHERE a.rolname = current_user) user_id_ok, (SELECT s.setting::int = f.sess_id FROM pg_settings s WHERE name = 'gp_session_id') cur_sess_id, content, size FROM tts_get_seg_files() f; -- $$ LANGUAGE SQL; CREATE -- No tables, the files list is empty diff --git a/src/test/isolation2/sql/temp_tables_stat.sql b/src/test/isolation2/sql/temp_tables_stat.sql index 547404f5d09..dbdfd3d177c 100644 --- a/src/test/isolation2/sql/temp_tables_stat.sql +++ b/src/test/isolation2/sql/temp_tables_stat.sql @@ -17,7 +17,7 @@ AS $$ WHERE name = 'gp_session_id') cur_sess_id, content, size - FROM tts_get_seg_files() f; /**/ + FROM tts_get_seg_files() f; -- $$ LANGUAGE SQL; -- No tables, the files list is empty From 40bd55a14a12e74a91accd5fb10bcaae4638506a Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Wed, 26 Nov 2025 13:51:49 +0300 Subject: [PATCH 12/14] Missing a file is not an error --- gpcontrib/temp_tables_stat/temp_tables_stat.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat.c b/gpcontrib/temp_tables_stat/temp_tables_stat.c index b17f397657a..1cc12bd7ea4 100644 --- a/gpcontrib/temp_tables_stat/temp_tables_stat.c +++ b/gpcontrib/temp_tables_stat/temp_tables_stat.c @@ -218,11 +218,8 @@ tts_get_file_size(const char *dirname, const char *fn_start) snprintf(fn, sizeof(fn), "%s/%s", dirname, direntry->d_name); if (stat(fn, &fst) < 0) - { - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not stat file \"%s\": %m", fn))); - } + continue; + dirsize += fst.st_size; } From 6d2469ad9f6cbdeb8393accc86156b87ee7bdd78 Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Wed, 26 Nov 2025 15:09:03 +0300 Subject: [PATCH 13/14] Add the get_node_to_append function --- gpcontrib/temp_tables_stat/temp_tables_stat.c | 59 +++++++++++-------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat.c b/gpcontrib/temp_tables_stat/temp_tables_stat.c index 1cc12bd7ea4..231d1902882 100644 --- a/gpcontrib/temp_tables_stat/temp_tables_stat.c +++ b/gpcontrib/temp_tables_stat/temp_tables_stat.c @@ -62,6 +62,38 @@ next_node(const TTSNode *node) return dsm_segment_address(dsm_seg); } +/* + * Returns the last node or a new node if the last one is full. + * Returns NULL when no need to add rnode to the list. + */ +static TTSNode * +get_node_to_append(RelFileNodeBackend rnode) +{ + for (TTSNode *node = &head->node;; node = next_node(node)) + { + /* Don't add rnode when it exists in the list of arrays */ + for (int i = 0; i < node->num; i++) + if (RelFileNodeBackendEquals(rnode, node->files[i])) + return NULL; + + if (node->next == DSM_HANDLE_INVALID) + { + /* Create a new node if the last node is full */ + if (node->num == ARRAY_SIZE(node->files)) + { + dsm_segment *next_seg = dsm_create(sizeof(TTSNode)); + dsm_pin_mapping(next_seg); + node->next = dsm_segment_handle(next_seg); + node = dsm_segment_address(next_seg); + node->next = DSM_HANDLE_INVALID; + node->num = 0; + } + + return node; + } + } +} + /* * This function is called with the same argument when each fork is created. * Add file info to the list if it is not there. @@ -81,31 +113,10 @@ tts_file_create_hook(RelFileNodeBackend rnode) LWLockAcquire(&head->lock, LW_EXCLUSIVE); - /* Don't add rnode when it exists in the list of arrays */ - for (node = &head->node;; node = next_node(node)) - { - for (int i = 0; i < node->num; i++) - if (RelFileNodeBackendEquals(rnode, node->files[i])) - goto lExit; - - if (node->next == DSM_HANDLE_INVALID) - break; - } + node = get_node_to_append(rnode); + if (node != NULL) + node->files[node->num++] = rnode; - /* Create a new node if the last node is full */ - if (node->num == ARRAY_SIZE(node->files)) - { - dsm_segment *next_seg = dsm_create(sizeof(TTSNode)); - dsm_pin_mapping(next_seg); - node->next = dsm_segment_handle(next_seg); - node = dsm_segment_address(next_seg); - node->next = DSM_HANDLE_INVALID; - node->num = 0; - } - - node->files[node->num++] = rnode; - -lExit: LWLockRelease(&head->lock); } From 5efe0ac7fa2e098224a7c0f2a99a079d4ae4a1c8 Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Wed, 26 Nov 2025 15:13:09 +0300 Subject: [PATCH 14/14] Fix --- gpcontrib/temp_tables_stat/temp_tables_stat.c | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/gpcontrib/temp_tables_stat/temp_tables_stat.c b/gpcontrib/temp_tables_stat/temp_tables_stat.c index 231d1902882..d2659f61dcb 100644 --- a/gpcontrib/temp_tables_stat/temp_tables_stat.c +++ b/gpcontrib/temp_tables_stat/temp_tables_stat.c @@ -76,21 +76,21 @@ get_node_to_append(RelFileNodeBackend rnode) if (RelFileNodeBackendEquals(rnode, node->files[i])) return NULL; - if (node->next == DSM_HANDLE_INVALID) - { - /* Create a new node if the last node is full */ - if (node->num == ARRAY_SIZE(node->files)) - { - dsm_segment *next_seg = dsm_create(sizeof(TTSNode)); - dsm_pin_mapping(next_seg); - node->next = dsm_segment_handle(next_seg); - node = dsm_segment_address(next_seg); - node->next = DSM_HANDLE_INVALID; - node->num = 0; - } + if (node->next != DSM_HANDLE_INVALID) + continue; - return node; + /* Create a new node if the last node is full */ + if (node->num == ARRAY_SIZE(node->files)) + { + dsm_segment *next_seg = dsm_create(sizeof(TTSNode)); + dsm_pin_mapping(next_seg); + node->next = dsm_segment_handle(next_seg); + node = dsm_segment_address(next_seg); + node->next = DSM_HANDLE_INVALID; + node->num = 0; } + + return node; } }