#include "postgres.h"

#include "access/table.h"
#include "fmgr.h"
#include "utils/rel.h"

PG_MODULE_MAGIC;

PG_FUNCTION_INFO_V1(repro_dml_safety);
PG_FUNCTION_INFO_V1(repro_dml_safety_cached);

Datum
repro_dml_safety(PG_FUNCTION_ARGS)
{
	Oid			relid = PG_GETARG_OID(0);
	Relation	rel;
	char		hazard;

	rel = table_open(relid, AccessShareLock);
	hazard = RelationGetParallelDmlSafety(rel);
	table_close(rel, AccessShareLock);

	PG_RETURN_CHAR(hazard);
}

Datum
repro_dml_safety_cached(PG_FUNCTION_ARGS)
{
	Oid			relid = PG_GETARG_OID(0);
	Relation	rel;
	char		hazard;

	rel = table_open(relid, AccessShareLock);
	hazard = rel->rd_paralleldml;
	table_close(rel, AccessShareLock);

	PG_RETURN_CHAR(hazard == 0 ? '0' : hazard);
}
