use strict; use warnings FATAL => 'all'; use PostgreSQL::Test::Cluster; use PostgreSQL::Test::Utils; use Test::More; my $node=PostgreSQL::Test::Cluster->new('g3a_index_oracle'); $node->init; $node->start; my $a=$node->background_psql('postgres'); my $b=$node->background_psql('postgres'); my $idx=$a->query_safe(q{SELECT 'pg_catalog.pg_class_relname_nsp_index'::regclass::oid;}); is($idx,'2663','exact system index identity'); $a->query_safe('CREATE TABLE public.g3a_persist(id int); INSERT INTO public.g3a_persist VALUES(42);'); for my $mode ('off','on'){ $a->query_safe("SET enable_temp_memory_catalog=$mode"); if($mode eq 'on'){ $a->query_safe('CREATE TEMP TABLE g3a_memory(id int); INSERT INTO g3a_memory VALUES(7);'); is($a->query_safe('SELECT id FROM g3a_memory'),'7','local object readable'); is($b->query_safe(q{SELECT to_regclass('pg_temp.g3a_memory') IS NULL}),'t','other session cannot see local object'); } $a->query_safe('BEGIN;'); my $before=$a->query_safe("SELECT pg_stat_get_xact_numscans($idx);"); my $res=$a->query_safe("SELECT count(to_regclass(format('public.g3a_missing_${mode}_%s',i))) FROM generate_series(1,20) i;"); my $after=$a->query_safe("SELECT pg_stat_get_xact_numscans($idx);"); my $delta=$after-$before; diag("INDEX_SCAN_DELTA $mode $before $after $delta"); is($res,'0',"$mode absent names return NULL"); cmp_ok($delta,'>=',20,"$mode physical index scans occur"); is($a->query_safe('SELECT id FROM public.g3a_persist'),'42',"$mode persistent table readable"); $a->query_safe('COMMIT;'); } # Both sources must remain correct after local rename and undo. $a->query_safe('BEGIN; SAVEPOINT rename_temp; ALTER TABLE g3a_memory RENAME TO g3a_renamed;'); is($a->query_safe(q{SELECT (to_regclass('pg_temp.g3a_memory') IS NULL AND to_regclass('pg_temp.g3a_renamed') IS NOT NULL)}),'t','local rename visible'); $a->query_safe('ROLLBACK TO rename_temp; RELEASE SAVEPOINT rename_temp; COMMIT;'); is($a->query_safe(q{SELECT (to_regclass('pg_temp.g3a_memory') IS NOT NULL AND to_regclass('pg_temp.g3a_renamed') IS NULL)}),'t','rollback restores local key'); is($a->query_safe('SELECT id FROM g3a_memory'),'7','local data survives rollback'); is($b->query_safe('SELECT id FROM public.g3a_persist'),'42','persistent row visible in second session'); is($b->query_safe(q{SELECT to_regclass('pg_temp.g3a_memory') IS NULL}),'t','local object remains private after rollback'); # The PostgreSQL startup switch still forces the physical heap fallback. my $fallback = $node->background_psql('postgres', connstr => $node->connstr('postgres') . " options='-c ignore_system_indexes=on -c client_min_messages=error'"); is($fallback->query_safe('SHOW ignore_system_indexes'),'on','native heap fallback requested'); $fallback->query_safe('SET enable_temp_memory_catalog=on; CREATE TEMP TABLE g3a_fallback(id int); INSERT INTO g3a_fallback VALUES(9);'); is($fallback->query_safe('SELECT id FROM g3a_fallback'),'9','fallback sees local row'); is($fallback->query_safe('SELECT id FROM public.g3a_persist'),'42','fallback sees physical row'); $fallback->query_safe('BEGIN;'); my $fb_before=$fallback->query_safe("SELECT pg_stat_get_xact_numscans($idx);"); is($fallback->query_safe(q{SELECT count(to_regclass(format('public.g3a_fallback_missing_%s',i))) FROM generate_series(1,20) i;}),'0','fallback absent names return NULL'); my $fb_after=$fallback->query_safe("SELECT pg_stat_get_xact_numscans($idx);"); is($fb_after-$fb_before,0,'native fallback does not scan physical index'); $fallback->query_safe('COMMIT;'); $fallback->quit; $a->quit; $b->quit; $node->stop; done_testing();