同步v3.0.5 gs_catalog_attribute_records

This commit is contained in:
梅程
2024-05-10 15:22:41 +08:00
committed by yaoxin
parent 7119d44e32
commit 102e675ecb
14 changed files with 225 additions and 6 deletions

View File

@ -52,6 +52,8 @@
#define MOT_FDW "mot_fdw"
#define MOT_FDW_SERVER "mot_server"
#define FirstBootstrapObjectId 10000
static bool describeOneTableDetails(const char* schemaname, const char* relationname, const char* oid, bool verbose);
static void add_tablespace_footer(printTableContent* const cont, char relkind, Oid tablespace, const bool newline);
static void add_role_attribute(PQExpBuffer buf, const char* const str);
@ -1736,7 +1738,12 @@ static bool describeOneTableDetails(const char* schemaname, const char* relation
} else {
appendPQExpBuffer(&buf, ", '' AS generated_column ");
}
appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a");
if (tableinfo.relkind == 'r' && atooid(oid) < FirstBootstrapObjectId) {
appendPQExpBuffer(&buf, "\nFROM (select * from pg_catalog.gs_catalog_attribute_records('%s')) as a", oid);
} else {
appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a");
}
appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped AND "
"a.attkvtype != 4 AND a.attname <> 'tableoid' AND a.attname <> 'tablebucketid'", oid);
appendPQExpBuffer(&buf, "\nORDER BY a.attnum;");

View File

@ -3615,6 +3615,10 @@
"gs_block_dw_io", 1,
AddBuiltinFunc(_0(4773), _1("gs_block_dw_io"), _2(2), _3(true), _4(true), _5(gs_block_dw_io), _6(16), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(1000), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(2, 23, 25), _21(3, 23, 25, 16), _22(3, 'i', 'i', 'o'), _23(3, "timeout", "identifier", "result"), _24(NULL), _25("gs_block_dw_io"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(false), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0))
),
AddFuncGroup(
"gs_catalog_attribute_records", 1,
AddBuiltinFunc(_0(8010), _1("gs_catalog_attribute_records"), _2(1), _3(true), _4(true), _5(gs_catalog_attribute_records), _6(2249), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(1000), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(1, 26), _21(26, 26, 26, 19, 26, 23, 21, 21, 23, 23, 23, 16, 18, 18, 16, 16, 16, 16, 5545, 23, 26, 1034, 1009, 1009, 17, 5545, 19), _22(26, 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(26, "relid", "attrelid", "attname", "atttypid", "attstattarget", "attlen", "attnum", "attndims", "attcacheoff", "atttypmod", "attbyval", "attstorage", "attalign", "attnotnull", "atthasdef", "attisdropped", "attislocal", "attcmprmode", "attinhcount", "attcollation", "attacl", "attoptions", "attfdwoptions", "attinitdefval", "attkvtype", "attdroppedname"), _24(NULL), _25("gs_catalog_attribute_records"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(false), _32(false), _33("attribute description for catalog relation"), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0))
),
AddFuncGroup(
"gs_cgroup_map_ng_conf", 1,
AddBuiltinFunc(_0(4503), _1("gs_cgroup_map_ng_conf"), _2(1), _3(false), _4(true), _5(gs_cgroup_map_ng_conf), _6(16), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(100), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(1, 2275), _21(NULL), _22(NULL), _23(NULL), _24(NULL), _25("gs_cgroup_map_ng_conf"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0))

View File

@ -60,6 +60,7 @@
#include "commands/tablespace.h"
#include "commands/directory.h"
#include "cstore.h"
#include "funcapi.h"
#include "storage/custorage.h"
#include "storage/page_compression.h"
#include "threadpool/threadpool.h"
@ -1319,4 +1320,105 @@ bool IsAformatStyleFunctionName(const char* schemaName)
}
}
return false;
}
}
/*
* Description: Get records in pg_attribte for system catalogs
* Returns: Datum
*/
Datum gs_catalog_attribute_records(PG_FUNCTION_ARGS)
{
FuncCallContext* funcctx = NULL;
if (SRF_IS_FIRSTCALL()) {
MemoryContext oldcontext = NULL;
TupleDesc tupdesc = NULL;
CatalogRelationBuildParam catalogparam = {InvalidOid};
Oid relid;
if (PG_ARGISNULL(0)) {
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("Parameter can not be null.")));
}
relid = PG_GETARG_OID(0);
if (relid >= FirstBootstrapObjectId) {
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("catalog oid should be less than %u", FirstBootstrapObjectId)));
}
catalogparam = GetCatalogParam(relid);
if (catalogparam.oid == InvalidOid) {
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("Oid %u does not belong to any catalog relation", relid)));
}
funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
Relation attrdesc = NULL;
attrdesc = heap_open(AttributeRelationId, AccessShareLock);
tupdesc = CopyTupleDesc(attrdesc->rd_att);
/* Schema of pg_attribute should not be allowed to change, so lock can be released earlier. */
heap_close(attrdesc, AccessShareLock);
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
funcctx->max_calls = catalogparam.natts;
funcctx->user_fctx = palloc(sizeof(CatalogRelationBuildParam));
*(CatalogRelationBuildParam *)(funcctx->user_fctx) = catalogparam;
(void)MemoryContextSwitchTo(oldcontext);
}
/* stuff done on every call of the function */
funcctx = SRF_PERCALL_SETUP();
while (funcctx->call_cntr < funcctx->max_calls) {
Datum values[Natts_pg_attribute];
bool nulls[Natts_pg_attribute];
HeapTuple tuple = NULL;
errno_t rc;
CatalogRelationBuildParam* catparamptr = (CatalogRelationBuildParam *)(funcctx->user_fctx);
FormData_pg_attribute attr = catparamptr->attrs[funcctx->call_cntr];
/* This is a tad tedious, but way cleaner than what we used to do... */
rc = memset_s(values, sizeof(values), 0, sizeof(values));
securec_check(rc, "\0", "\0");
rc = memset_s(nulls, sizeof(nulls), false, sizeof(nulls));
securec_check(rc, "\0", "\0");
values[Anum_pg_attribute_attrelid - 1] = ObjectIdGetDatum(attr.attrelid);
values[Anum_pg_attribute_attname - 1] = NameGetDatum(&attr.attname);
values[Anum_pg_attribute_atttypid - 1] = ObjectIdGetDatum(attr.atttypid);
values[Anum_pg_attribute_attstattarget - 1] = Int32GetDatum(attr.attstattarget);
values[Anum_pg_attribute_attlen - 1] = Int16GetDatum(attr.attlen);
values[Anum_pg_attribute_attnum - 1] = Int16GetDatum(attr.attnum);
values[Anum_pg_attribute_attndims - 1] = Int32GetDatum(attr.attndims);
values[Anum_pg_attribute_attcacheoff - 1] = Int32GetDatum(attr.attcacheoff);
values[Anum_pg_attribute_atttypmod - 1] = Int32GetDatum(attr.atttypmod);
values[Anum_pg_attribute_attbyval - 1] = BoolGetDatum(attr.attbyval);
values[Anum_pg_attribute_attstorage - 1] = CharGetDatum(attr.attstorage);
values[Anum_pg_attribute_attalign - 1] = CharGetDatum(attr.attalign);
values[Anum_pg_attribute_attnotnull - 1] = BoolGetDatum(attr.attnotnull);
values[Anum_pg_attribute_atthasdef - 1] = BoolGetDatum(attr.atthasdef);
values[Anum_pg_attribute_attisdropped - 1] = BoolGetDatum(attr.attisdropped);
values[Anum_pg_attribute_attislocal - 1] = BoolGetDatum(attr.attislocal);
values[Anum_pg_attribute_attcmprmode - 1] = Int8GetDatum(attr.attcmprmode);
values[Anum_pg_attribute_attinhcount - 1] = Int32GetDatum(attr.attinhcount);
values[Anum_pg_attribute_attcollation - 1] = ObjectIdGetDatum(attr.attcollation);
/* kvtype of catalog relations is always 0 */
values[Anum_pg_attribute_attkvtype - 1] = Int8GetDatum(0);
values[Anum_pg_attribute_attdroppedname - 1] = NameGetDatum(&attr.attdroppedname);
/* Variable length attribute fields have little significance for catalog relations */
nulls[Anum_pg_attribute_attacl - 1] = true;
nulls[Anum_pg_attribute_attoptions - 1] = true;
nulls[Anum_pg_attribute_attfdwoptions - 1] = true;
nulls[Anum_pg_attribute_attinitdefval - 1] = true;
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));
}
SRF_RETURN_DONE(funcctx);
}

View File

@ -32,6 +32,7 @@
#include <sys/file.h>
#include <catalog/pg_obsscaninfo.h>
#include <catalog/gs_obsscaninfo.h>
#include "access/reloptions.h"
#include "access/sysattr.h"
@ -294,6 +295,7 @@ static const FormData_pg_attribute Desc_pg_extension_data_source[Natts_pg_extens
Schema_pg_extension_data_source};
static const FormData_pg_attribute Desc_pg_directory[Natts_pg_directory] = {Schema_pg_directory};
static const FormData_pg_attribute Desc_pg_obsscaninfo[Natts_pg_obsscaninfo] = {Schema_pg_obsscaninfo};
static const FormData_pg_attribute Desc_gs_obsscaninfo[Natts_gs_obsscaninfo] = {Schema_gs_obsscaninfo};
static const FormData_pg_attribute Desc_pgxc_class[Natts_pgxc_class] = {Schema_pgxc_class};
static const FormData_pg_attribute Desc_pgxc_group[Natts_pgxc_group] = {Schema_pgxc_group};
static const FormData_pg_attribute Desc_pgxc_node[Natts_pgxc_node] = {Schema_pgxc_node};
@ -869,6 +871,15 @@ static struct CatalogRelationBuildParam catalogBuildParam[CATALOG_NUM] = {{Defau
Desc_pg_obsscaninfo,
false,
true},
{GSObsScanInfoRelationId,
"gs_obsscaninfo",
GSObsScanInfoRelation_Rowtype_Id,
true,
false,
Natts_gs_obsscaninfo,
Desc_gs_obsscaninfo,
false,
true},
{GsGlobalChainRelationId,
"gs_global_chain",
GsGlobalChainRelationId_Rowtype_Id,

View File

@ -75,7 +75,7 @@ bool will_shutdown = false;
* NEXT | 92899 | ? | ?
*
********************************************/
const uint32 GRAND_VERSION_NUM = 92928;
const uint32 GRAND_VERSION_NUM = 92929;
/********************************************
* 2.VERSION NUM FOR EACH FEATURE

View File

@ -62,6 +62,6 @@
#define NAILED_IN_CATALOG_NUM 8
#define CATALOG_NUM 108
#define CATALOG_NUM 109
#endif

View File

@ -41,7 +41,7 @@
#define GSObsScanInfoRelationId 5680
#define GSObsScanInfoRelation_Rowtype_Id 11661
CATALOG(gs_obsscaninfo,5680) BKI_SHARED_RELATION BKI_WITHOUT_OIDS
CATALOG(gs_obsscaninfo,5680) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO
{
/* These fields form the unique key for the entry: */
int8 query_id;

View File

@ -0,0 +1 @@
DROP FUNCTION IF EXISTS pg_catalog.gs_catalog_attribute_records(oid);

View File

@ -0,0 +1 @@
DROP FUNCTION IF EXISTS pg_catalog.gs_catalog_attribute_records(oid);

View File

@ -0,0 +1,30 @@
DROP FUNCTION IF EXISTS pg_catalog.gs_catalog_attribute_records(oid);
SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 8010;
CREATE OR REPLACE FUNCTION pg_catalog.gs_catalog_attribute_records(
IN relid oid,
OUT attrelid oid,
OUT attname name,
OUT atttypid oid,
OUT attstattarget integer,
OUT attlen smallint,
OUT attnum smallint,
OUT attndims integer,
OUT attcacheoff integer,
OUT atttypmod integer,
OUT attbyval boolean,
OUT attstorage "char",
OUT attalign "char",
OUT attnotnull boolean,
OUT atthasdef boolean,
OUT attisdropped boolean,
OUT attislocal boolean,
OUT attcmprmode tinyint,
OUT attinhcount integer,
OUT attcollation oid,
OUT attacl aclitem [],
OUT attoptions text [],
OUT attfdwoptions text [],
OUT attinitdefval bytea,
OUT attkvtype tinyint,
OUT attdroppedname name
) RETURNS SETOF RECORD STRICT STABLE ROWS 1000 LANGUAGE INTERNAL AS 'gs_catalog_attribute_records';

View File

@ -0,0 +1,30 @@
DROP FUNCTION IF EXISTS pg_catalog.gs_catalog_attribute_records(oid);
SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 8010;
CREATE OR REPLACE FUNCTION pg_catalog.gs_catalog_attribute_records(
IN relid oid,
OUT attrelid oid,
OUT attname name,
OUT atttypid oid,
OUT attstattarget integer,
OUT attlen smallint,
OUT attnum smallint,
OUT attndims integer,
OUT attcacheoff integer,
OUT atttypmod integer,
OUT attbyval boolean,
OUT attstorage "char",
OUT attalign "char",
OUT attnotnull boolean,
OUT atthasdef boolean,
OUT attisdropped boolean,
OUT attislocal boolean,
OUT attcmprmode tinyint,
OUT attinhcount integer,
OUT attcollation oid,
OUT attacl aclitem [],
OUT attoptions text [],
OUT attfdwoptions text [],
OUT attinitdefval bytea,
OUT attkvtype tinyint,
OUT attdroppedname name
) RETURNS SETOF RECORD STRICT STABLE ROWS 1000 LANGUAGE INTERNAL AS 'gs_catalog_attribute_records';

View File

@ -0,0 +1,31 @@
\d gs_obsscaninfo
Table "pg_catalog.gs_obsscaninfo"
Column | Type | Modifiers
--------------+--------------------------+-----------
query_id | bigint | not null
user_id | text |
table_name | text |
file_type | text |
time_stamp | timestamp with time zone |
actual_time | double precision |
file_scanned | bigint |
data_size | double precision |
billing_info | text |
Replica Identity: NOTHING
Tablespace: "pg_global"
\d pg_obsscaninfo
Table "pg_catalog.pg_obsscaninfo"
Column | Type | Modifiers
--------------+--------------------------+-----------
query_id | bigint | not null
user_id | text |
table_name | text |
file_type | text |
time_stamp | timestamp with time zone |
actual_time | double precision |
file_scanned | bigint |
data_size | double precision |
billing_info | text |
Replica Identity: NOTHING

View File

@ -414,7 +414,7 @@ test: partiton_pathkey_col_plan partiton_pathkey_col_randomexec partiton_pathkey
#test: type_sanity
#test: create_function_1
test: create_table create_table_2 create_table_3
test: temp__4
test: temp__4 obsscaninfo
test: create_seg_table
#test: copy#

View File

@ -0,0 +1,2 @@
\d gs_obsscaninfo
\d pg_obsscaninfo