Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contrib/amcheck/verify_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "catalog/pg_am.h"
#include "commands/defrem.h"
#include "commands/tablecmds.h"
#include "doltgres/hooks.h"
#include "utils/guc.h"
#include "utils/syscache.h"

Expand Down Expand Up @@ -167,7 +168,7 @@ index_checkable(Relation rel, Oid am_id)
errmsg("expected index as targets for verification"),
errdetail_relkind_not_supported(rel->rd_rel->relkind)));

if (rel->rd_rel->relam != am_id)
if (rel->rd_rel->relam != am_id || doltgres_heap_only_refused(rel))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("expected \"%s\" index as targets for verification", get_am_name(am_id)),
Expand Down
5 changes: 3 additions & 2 deletions contrib/amcheck/verify_heapam.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "access/xact.h"
#include "catalog/pg_am.h"
#include "catalog/pg_class.h"
#include "doltgres/hooks.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
Expand Down Expand Up @@ -344,8 +345,8 @@ verify_heapam(PG_FUNCTION_ARGS)
* Sequences always use heap AM, but they don't show that in the catalogs.
* Other relkinds might be using a different AM, so check.
*/
if (ctx.rel->rd_rel->relkind != RELKIND_SEQUENCE &&
ctx.rel->rd_rel->relam != HEAP_TABLE_AM_OID)
if ((ctx.rel->rd_rel->relkind != RELKIND_SEQUENCE &&
ctx.rel->rd_rel->relam != HEAP_TABLE_AM_OID) || doltgres_heap_only_refused(ctx.rel))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("only heap AM is supported")));
Expand Down
3 changes: 2 additions & 1 deletion contrib/pageinspect/brinfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "access/htup_details.h"
#include "catalog/pg_am_d.h"
#include "catalog/pg_type.h"
#include "doltgres/hooks.h"
#include "funcapi.h"
#include "lib/stringinfo.h"
#include "miscadmin.h"
Expand Down Expand Up @@ -165,7 +166,7 @@ brin_page_items(PG_FUNCTION_ARGS)

indexRel = index_open(indexRelid, AccessShareLock);

if (!IS_BRIN(indexRel))
if (!IS_BRIN(indexRel) || doltgres_heap_only_refused(indexRel))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a %s index",
Expand Down
5 changes: 3 additions & 2 deletions contrib/pageinspect/btreefuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "catalog/namespace.h"
#include "catalog/pg_am.h"
#include "catalog/pg_type.h"
#include "doltgres/hooks.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "pageinspect.h"
Expand Down Expand Up @@ -225,7 +226,7 @@ check_relation_block_range(Relation rel, int64 blkno)
static void
bt_index_block_validate(Relation rel, int64 blkno)
{
if (!IS_INDEX(rel) || !IS_BTREE(rel))
if (!IS_INDEX(rel) || !IS_BTREE(rel) || doltgres_heap_only_refused(rel))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a %s index",
Expand Down Expand Up @@ -858,7 +859,7 @@ bt_metap(PG_FUNCTION_ARGS)
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
rel = relation_openrv(relrv, AccessShareLock);

if (!IS_INDEX(rel) || !IS_BTREE(rel))
if (!IS_INDEX(rel) || !IS_BTREE(rel) || doltgres_heap_only_refused(rel))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a %s index",
Expand Down
3 changes: 2 additions & 1 deletion contrib/pageinspect/gistfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "access/htup_details.h"
#include "access/relation.h"
#include "catalog/pg_am_d.h"
#include "doltgres/hooks.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "pageinspect.h"
Expand Down Expand Up @@ -218,7 +219,7 @@ gist_page_items(PG_FUNCTION_ARGS)
/* Open the relation */
indexRel = index_open(indexRelid, AccessShareLock);

if (!IS_GIST(indexRel))
if (!IS_GIST(indexRel) || doltgres_heap_only_refused(indexRel))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a %s index",
Expand Down
3 changes: 2 additions & 1 deletion contrib/pageinspect/hashfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "access/relation.h"
#include "catalog/pg_am.h"
#include "catalog/pg_type.h"
#include "doltgres/hooks.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "pageinspect.h"
Expand Down Expand Up @@ -421,7 +422,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
*/
indexRel = relation_open(indexRelid, AccessShareLock);

if (!IS_INDEX(indexRel) || !IS_HASH(indexRel))
if (!IS_INDEX(indexRel) || !IS_HASH(indexRel) || doltgres_heap_only_refused(indexRel))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a %s index",
Expand Down
5 changes: 3 additions & 2 deletions contrib/pageinspect/heapfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "access/relation.h"
#include "catalog/pg_am_d.h"
#include "catalog/pg_type.h"
#include "doltgres/hooks.h"
#include "funcapi.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
Expand Down Expand Up @@ -325,8 +326,8 @@ tuple_data_split_internal(Oid relid, char *tupdata,
/*
* Sequences always use heap AM, but they don't show that in the catalogs.
*/
if (rel->rd_rel->relkind != RELKIND_SEQUENCE &&
rel->rd_rel->relam != HEAP_TABLE_AM_OID)
if ((rel->rd_rel->relkind != RELKIND_SEQUENCE &&
rel->rd_rel->relam != HEAP_TABLE_AM_OID) || doltgres_heap_only_refused(rel))
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("only heap AM is supported")));

Expand Down
4 changes: 3 additions & 1 deletion contrib/pageinspect/rawpage.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "access/relation.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "doltgres/hooks.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "pageinspect.h"
Expand Down Expand Up @@ -158,7 +159,8 @@ get_raw_page_internal(text *relname, ForkNumber forknum, BlockNumber blkno)
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
rel = relation_openrv(relrv, AccessShareLock);

if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind) ||
(forknum == MAIN_FORKNUM && doltgres_heap_only_refused(rel)))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot get raw page from relation \"%s\"",
Expand Down
3 changes: 2 additions & 1 deletion contrib/pg_surgery/heap_surgery.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "access/xloginsert.h"
#include "catalog/pg_am_d.h"
#include "catalog/pg_control.h"
#include "doltgres/hooks.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
#include "utils/acl.h"
Expand Down Expand Up @@ -116,7 +117,7 @@ heap_force_common(FunctionCallInfo fcinfo, HeapTupleForceOption heap_force_opt)
RelationGetRelationName(rel)),
errdetail_relkind_not_supported(rel->rd_rel->relkind)));

if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
if (rel->rd_rel->relam != HEAP_TABLE_AM_OID || doltgres_heap_only_refused(rel))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("only heap AM is supported")));
Expand Down
49 changes: 44 additions & 5 deletions contrib/pg_visibility/pg_visibility.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "access/xloginsert.h"
#include "catalog/pg_type.h"
#include "catalog/storage_xlog.h"
#include "doltgres/hooks.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
Expand Down Expand Up @@ -105,6 +106,7 @@ pg_visibility_map(PG_FUNCTION_ARGS)
tupdesc = pg_visibility_tupdesc(false, false);

mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
mapbits = doltgres_visibility_bits(rel, blkno, mapbits);
if (vmbuffer != InvalidBuffer)
ReleaseBuffer(vmbuffer);
values[0] = BoolGetDatum((mapbits & VISIBILITYMAP_ALL_VISIBLE) != 0);
Expand Down Expand Up @@ -146,13 +148,15 @@ pg_visibility(PG_FUNCTION_ARGS)
tupdesc = pg_visibility_tupdesc(false, true);

mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
mapbits = doltgres_visibility_bits(rel, blkno, mapbits);
if (vmbuffer != InvalidBuffer)
ReleaseBuffer(vmbuffer);
values[0] = BoolGetDatum((mapbits & VISIBILITYMAP_ALL_VISIBLE) != 0);
values[1] = BoolGetDatum((mapbits & VISIBILITYMAP_ALL_FROZEN) != 0);

/* Here we have to explicitly check rel size ... */
if (blkno < RelationGetNumberOfBlocks(rel))
if (blkno < RelationGetNumberOfBlocks(rel) &&
!doltgres_visibility_kept(rel))
{
buffer = ReadBuffer(rel, blkno);
LockBuffer(buffer, BUFFER_LOCK_SHARE);
Expand All @@ -165,14 +169,32 @@ pg_visibility(PG_FUNCTION_ARGS)
else
{
/* As with the vismap, silently return 0 for pages past EOF */
values[2] = BoolGetDatum(false);
if (!doltgres_visibility_page(rel, blkno, &values[2]))
{
values[2] = BoolGetDatum(false);
}
}

relation_close(rel, AccessShareLock);

PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
}

/*
* doltgres_visibility_page gives pg_visibility's page-level all-visible flag
* of a fork table's block, set for each block within the table since the
* fork has no pages and keeps every block all-visible, answering whether the
* fork stores the table.
*/
bool
doltgres_visibility_page(Relation rel, BlockNumber blkno, Datum *all_visible)
{
if (!doltgres_visibility_kept(rel))
return false;
*all_visible = BoolGetDatum(blkno < RelationGetNumberOfBlocks(rel));
return true;
}

/*
* Visibility map information for every block in a relation.
*/
Expand Down Expand Up @@ -503,7 +525,8 @@ collect_visibility_data(Oid relid, bool include_pd)
info->count = nblocks;

/* Create a stream if reading main fork. */
if (include_pd)
if (include_pd &&
!doltgres_visibility_kept(rel))
{
p.current_blocknum = 0;
p.last_exclusive = nblocks;
Expand Down Expand Up @@ -541,7 +564,8 @@ collect_visibility_data(Oid relid, bool include_pd)
* caller needs it. Use a buffer access strategy, too, to prevent
* cache-trashing.
*/
if (include_pd)
if (include_pd &&
!doltgres_visibility_kept(rel))
{
Buffer buffer;
Page page;
Expand All @@ -557,11 +581,13 @@ collect_visibility_data(Oid relid, bool include_pd)
}
}

if (include_pd)
if (include_pd &&
!doltgres_visibility_kept(rel))
{
Assert(read_stream_next_buffer(stream, NULL) == InvalidBuffer);
read_stream_end(stream);
}
doltgres_visibility_collected(rel, include_pd, info);

/* Clean up. */
if (vmbuffer != InvalidBuffer)
Expand All @@ -571,6 +597,19 @@ collect_visibility_data(Oid relid, bool include_pd)
return info;
}

/*
* doltgres_visibility_collected sets each block of a fork table all-visible
* and all-frozen in collect_visibility_data's bits, and all-visible on its
* page too when the caller asked for pages, since the fork keeps no
* visibility map and has no pages to read.
*/
void
doltgres_visibility_collected(Relation rel, bool include_pd, vbits *info)
{
if (doltgres_visibility_kept(rel))
memset(info->bits, include_pd ? (1 << 0) | (1 << 1) | (1 << 2) : (1 << 0) | (1 << 1), info->count);
}

/*
* The "strict" version of GetOldestNonRemovableTransactionId(). The
* pg_visibility check can tolerate false positives (don't report some of the
Expand Down
3 changes: 2 additions & 1 deletion contrib/pgstattuple/pgstatapprox.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "access/visibilitymap.h"
#include "catalog/pg_am_d.h"
#include "commands/vacuum.h"
#include "doltgres/hooks.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
Expand Down Expand Up @@ -345,7 +346,7 @@ pgstattuple_approx_internal(Oid relid, FunctionCallInfo fcinfo)
RelationGetRelationName(rel)),
errdetail_relkind_not_supported(rel->rd_rel->relkind)));

if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
if (rel->rd_rel->relam != HEAP_TABLE_AM_OID || doltgres_heap_only_refused(rel))
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("only heap AM is supported")));

Expand Down
7 changes: 4 additions & 3 deletions contrib/pgstattuple/pgstatindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "access/relation.h"
#include "catalog/namespace.h"
#include "catalog/pg_am.h"
#include "doltgres/hooks.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
Expand Down Expand Up @@ -222,7 +223,7 @@ pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
ReadStream *stream;
BlockNumber startblk;

if (!IS_INDEX(rel) || !IS_BTREE(rel))
if (!IS_INDEX(rel) || !IS_BTREE(rel) || doltgres_heap_only_refused(rel))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("relation \"%s\" is not a btree index",
Expand Down Expand Up @@ -541,7 +542,7 @@ pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
*/
rel = relation_open(relid, AccessShareLock);

if (!IS_INDEX(rel) || !IS_GIN(rel))
if (!IS_INDEX(rel) || !IS_GIN(rel) || doltgres_heap_only_refused(rel))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("relation \"%s\" is not a GIN index",
Expand Down Expand Up @@ -631,7 +632,7 @@ pgstathashindex(PG_FUNCTION_ARGS)
*/
rel = relation_open(relid, AccessShareLock);

if (!IS_INDEX(rel) || !IS_HASH(rel))
if (!IS_INDEX(rel) || !IS_HASH(rel) || doltgres_heap_only_refused(rel))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("relation \"%s\" is not a hash index",
Expand Down
7 changes: 4 additions & 3 deletions contrib/pgstattuple/pgstattuple.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "access/tableam.h"
#include "catalog/namespace.h"
#include "catalog/pg_am_d.h"
#include "doltgres/hooks.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
Expand Down Expand Up @@ -268,7 +269,7 @@ pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
errmsg("index \"%s\" is not valid",
RelationGetRelationName(rel))));

switch (rel->rd_rel->relam)
switch (doltgres_heap_only_refused(rel) ? InvalidOid : rel->rd_rel->relam)
{
case BTREE_AM_OID:
return pgstat_index(rel, BTREE_METAPAGE + 1,
Expand Down Expand Up @@ -328,8 +329,8 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
/*
* Sequences always use heap AM, but they don't show that in the catalogs.
*/
if (rel->rd_rel->relkind != RELKIND_SEQUENCE &&
rel->rd_rel->relam != HEAP_TABLE_AM_OID)
if ((rel->rd_rel->relkind != RELKIND_SEQUENCE &&
rel->rd_rel->relam != HEAP_TABLE_AM_OID) || doltgres_heap_only_refused(rel))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("only heap AM is supported")));
Expand Down
4 changes: 4 additions & 0 deletions src/backend/access/heap/visibilitymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
#include "access/visibilitymap.h"
#include "access/xloginsert.h"
#include "access/xlogutils.h"
#include "doltgres/hooks.h"
#include "miscadmin.h"
#include "port/pg_bitutils.h"
#include "storage/bufmgr.h"
Expand Down Expand Up @@ -379,6 +380,9 @@ visibilitymap_count(Relation rel, BlockNumber *all_visible, BlockNumber *all_fro
/* all_visible must be specified */
Assert(all_visible);

if (doltgres_visibility_counted(rel, all_visible, all_frozen))
return;

for (mapBlock = 0;; mapBlock++)
{
Buffer mapBuffer;
Expand Down
Loading
Loading