Skip to content
Permalink
Browse files
HAWQ-1822. Enable heap table
  • Loading branch information
ztao1987 committed Dec 15, 2021
1 parent 7947f7e commit 4f67d22e1cd242a4be2660d0eda20e8cbe1c926f
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 17 deletions.
@@ -409,7 +409,7 @@ Datum magma_protocol_blocklocation(PG_FUNCTION_ARGS) {
MagmaTablePtr table = MagmaClientC_FetchTable(client, useClientCacheDirectly);
magma_check_result(&client);

elog(LOG, "magma_protocol_blocklocation pass fetch table");
elog(DEBUG3, "magma_protocol_blocklocation pass fetch table");

/*
* Step 3. map ranges to block locations
@@ -755,8 +755,8 @@ DefineIndex(Oid relationId,
}
else
{
/* magma and native orc support index */
if (!(RelationIsOrc(rel) || RelationIsMagmaTable2(relationId)))
/* Native orc, heap table and magma support index */
if (!RelationIsOrc(rel) && !RelationIsHeap(rel) && !RelationIsMagmaTable(relationId))
{
ereport(ERROR, (errcode(ERRCODE_CDB_FEATURE_NOT_YET), errmsg("Cannot support DefineIndex")));
}
@@ -499,8 +499,8 @@ DefineRelation(CreateStmt *stmt, char relkind, char relstorage,
Oid reloid = 0;
Assert(stmt->base.relation->schemaname == NULL || strlen(stmt->base.relation->schemaname)>0);

/* forbid create non-system table on tablespace pg_default */
if((!IsBootstrapProcessingMode()) && (isPgDefaultTablespace(stmt->base.tablespacename)))
/* forbid create non-system table on tablespace pg_default when enable_pg_default_for_non_system_table is not true */
if(!enable_pg_default_for_non_system_table && (!IsBootstrapProcessingMode()) && (isPgDefaultTablespace(stmt->base.tablespacename)))
{
ereport(ERROR,
(errcode(ERRCODE_CDB_FEATURE_NOT_YET),
@@ -605,11 +605,13 @@ DefineRelation_int(CreateStmt *stmt,
* dispatch.
*/
if (pg_strcasecmp("pg_default", stmt->base.tablespacename) == 0)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("can not create ao format table on tablespace \"%s\" ",
stmt->base.tablespacename),
errOmitLocation(true)));
if (!enable_pg_default_for_non_system_table) {
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("can not create ao format table on tablespace \"%s\" ",
stmt->base.tablespacename),
errOmitLocation(true)));
}

tablespaceId = get_tablespace_oid(stmt->base.tablespacename);
if (!OidIsValid(tablespaceId))
@@ -3138,7 +3138,20 @@ static void transformDistributedBy(ParseState *pstate, CreateStmtContext *cxt,
*policyp = NULL;
return;
}


/*
* Currently heap table only exists in hawq's master, so there is no
* policy information.
*/
if (enable_heap_table_on_master) {
bool appendonly;
bool hasAppendOnly = GetRelOpt_appendonly_fromOptions(options, &appendonly);
if (hasAppendOnly && !appendonly) {
*policyp = NULL;
return;
}
}

policy = (GpPolicy *)palloc(sizeof(GpPolicy) +
maxattrs * sizeof(policy->attrs[0]));
policy->ptype = POLICYTYPE_PARTITIONED;
@@ -535,6 +535,29 @@ int GetRelOpt_bucket_num_fromOptions(List *options, int default_val)
}
return ((bucketnum>0)?bucketnum : (default_val));
}

/*
* If appendonly is set, return true, otherwise return false.
*/
bool GetRelOpt_appendonly_fromOptions(List *options, bool *appendonly)
{
ListCell *cell;
/* Scan list to see if "appendonly" was included */
if(options)
foreach(cell, options)
{
DefElem *def = (DefElem *) lfirst(cell);

if (pg_strcasecmp(def->defname, "appendonly") == 0)
{
bool need_free_arg = false;
*appendonly = defGetString(def, &need_free_arg) == "true";
return true;
}
}
return false;
}

/**
* Read Relation Option from catalog Relation
*/
@@ -417,20 +417,24 @@ QueryIsReadOnly(Query *parsetree)

/*
* CanCreateIndex: can support create index
* So far, magma table and native orc could support index
* So far, magma table, native orc and heap table could support index
*/
void CanSupportIndex(IndexStmt *stmt, Oid relid)
{
/* 1. upgrade mode should support index operation */
if (gp_upgrade_mode) return;

bool supportIndex = false;
Relation rel = heap_open(relid, AccessShareLock);
bool nativeOrc = RelationIsOrc(rel);
bool isHeap = RelationIsHeap(rel);
heap_close(rel, AccessShareLock);

/* 2. heap table supports index */
if (isHeap) return;

/*
* 2. deal magma table and native orc
* 3. deal magma table and native orc
* for "stmt->magma", deal with special partition situation, oushu issue #1049
* its ugly, but there is no elegant way now
*/
@@ -446,7 +450,7 @@ void CanSupportIndex(IndexStmt *stmt, Oid relid)
if (supportIndex)
{
/*
* 3. magma/native orc index cant support the accessory conditions
* 4. magma/native orc index cant support the accessory conditions
*/
if (stmt->options) {
ereport(ERROR,
@@ -1301,9 +1301,10 @@ RelationBuildDesc(Oid targetRelId, bool insertIt)

/*
* initialize Greenplum Database partitioning info
* currently heap table only exists in hawq's master, so there is no rd_cdbpolicy.
*/
if (relation->rd_rel->relkind == RELKIND_RELATION &&
!IsSystemRelation(relation))
!IsSystemRelation(relation) && !RelationIsHeap(relation))
relation->rd_cdbpolicy = GpPolicyFetch(CacheMemoryContext, targetRelId);

relation->rd_cdbDefaultStatsWarningIssued = false;
@@ -773,6 +773,8 @@ int hawq_rm_nvseg_for_analyze_nopart_perquery_perseg_limit;
int hawq_rm_nvseg_for_analyze_part_perquery_perseg_limit;
int hawq_rm_nvseg_for_analyze_nopart_perquery_limit;
int hawq_rm_nvseg_for_analyze_part_perquery_limit;
bool enable_heap_table_on_master;
bool enable_pg_default_for_non_system_table;
double optimizer_cost_threshold;
double optimizer_nestloop_factor;
double locality_upper_bound;
@@ -4581,6 +4583,25 @@ static struct config_bool ConfigureNamesBool[] =
&hawq_init_with_hdfs,
true, NULL, NULL
},

{
{"enable_heap_table_on_master", PGC_USERSET, DEVELOPER_OPTIONS,
gettext_noop("Enable heap tables on the master."),
NULL,
GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
},
&enable_heap_table_on_master,
false, NULL, NULL
},
{
{"enable_pg_default_for_non_system_table", PGC_USERSET, DEVELOPER_OPTIONS,
gettext_noop("Enable pg_default for non-system tables."),
NULL,
GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
},
&enable_pg_default_for_non_system_table,
false, NULL, NULL
},

/* End-of-list marker */
{
@@ -246,7 +246,7 @@ DESCR("");
#define RELSTORAGE_EXTERNAL 'x'
#define RELSTORAGE_FOREIGN 'f'

static inline bool relstorage_is_buffer_pool(char c)
static inline bool relstorage_is_heap(char c)
{
return (c == RELSTORAGE_HEAP);
}
@@ -94,6 +94,7 @@ extern int GetUserDefinedFunctionVsegNum(void);
extern int GetAnalyzeVSegNum(void);
extern int GetCopyFromVSegNum(void);
extern int GetRelOpt_bucket_num_fromOptions(List *options, int default_val);
extern bool GetRelOpt_appendonly_fromOptions(List *options, bool *appendonly);
extern int GetRelOpt_bucket_num_fromRel(Relation relation, int default_val);
extern int GetRelOpt_bucket_num_fromRangeVar(const RangeVar* rel_rv, int default_val);
extern int GetDefaultPartitionNum(void);
@@ -322,6 +322,15 @@ extern int hawq_rm_nvseg_for_analyze_nopart_perquery_perseg_limit;
extern int hawq_rm_nvseg_for_analyze_part_perquery_perseg_limit;
extern int hawq_rm_nvseg_for_analyze_nopart_perquery_limit;
extern int hawq_rm_nvseg_for_analyze_part_perquery_limit;

/////////////////////////////////////////////////////////////////////////
/*
* These guc and related code are temporary, maybe will be delete afterwords.
*/
extern bool enable_heap_table_on_master;
extern bool enable_pg_default_for_non_system_table;
/////////////////////////////////////////////////////////////////////////

extern bool allow_file_count_bucket_num_mismatch;
extern bool enable_pg_stat_activity_history;

0 comments on commit 4f67d22

Please sign in to comment.