Formatting, naming, comments
This commit is contained in:
parent
7bc34dfa90
commit
5b95cfddf4
1 changed files with 35 additions and 19 deletions
54
matview.c
54
matview.c
|
|
@ -233,7 +233,7 @@ static void clean_up_IVM_hash_entry(MV_TriggerHashEntry *entry, bool is_abort,
|
||||||
static void setLastUpdateXid(Oid immv_oid, FullTransactionId xid);
|
static void setLastUpdateXid(Oid immv_oid, FullTransactionId xid);
|
||||||
static FullTransactionId getLastUpdateXid(Oid immv_oid);
|
static FullTransactionId getLastUpdateXid(Oid immv_oid);
|
||||||
|
|
||||||
static Query *recreate_immv_query(Relation matviewRel);
|
static Query *update_immv_viewdef(Relation matviewRel);
|
||||||
|
|
||||||
/* SQL callable functions */
|
/* SQL callable functions */
|
||||||
PG_FUNCTION_INFO_V1(IVM_immediate_before);
|
PG_FUNCTION_INFO_V1(IVM_immediate_before);
|
||||||
|
|
@ -389,7 +389,18 @@ RefreshImmvByOid(Oid matviewOid, bool is_create, bool skipData,
|
||||||
systable_endscan(scan);
|
systable_endscan(scan);
|
||||||
table_close(pgIvmImmv, NoLock);
|
table_close(pgIvmImmv, NoLock);
|
||||||
|
|
||||||
viewQuery = recreate_immv_query(matviewRel);
|
/*
|
||||||
|
* Recreate the Query tree from the query string to account for changing
|
||||||
|
* base table OIDs (e.g. after dump/restore) or changing format of the Query
|
||||||
|
* node (after pg_upgrade).
|
||||||
|
*
|
||||||
|
* No need to create the Query tree a second time if we are creating a new
|
||||||
|
* IMMV.
|
||||||
|
*/
|
||||||
|
if (is_create)
|
||||||
|
viewQuery = get_immv_query(matviewRel);
|
||||||
|
else
|
||||||
|
viewQuery = update_immv_viewdef(matviewRel);
|
||||||
|
|
||||||
/* For IMMV, we need to rewrite matview query */
|
/* For IMMV, we need to rewrite matview query */
|
||||||
if (!skipData)
|
if (!skipData)
|
||||||
|
|
@ -719,34 +730,36 @@ get_immv_query(Relation matviewRel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* recreate_immv_query
|
* update_immv_viewdef
|
||||||
*
|
*
|
||||||
* Parse the querystring for this IMMV. Update the viewdef column in
|
* Read the query string for this IMMV from pg_ivm_immv. Parse the query string
|
||||||
* pg_ivm_immv and return the Query tree.
|
* and update the viewdef column with the new Query tree. Return the Query
|
||||||
|
* tree.
|
||||||
*/
|
*/
|
||||||
static Query *
|
static Query *
|
||||||
recreate_immv_query(Relation matviewRel)
|
update_immv_viewdef(Relation matviewRel)
|
||||||
{
|
{
|
||||||
Relation pgIvmImmv = table_open(PgIvmImmvRelationId(), AccessShareLock);
|
CreateTableAsStmt *stmt;
|
||||||
TupleDesc tupdesc = RelationGetDescr(pgIvmImmv);
|
|
||||||
SysScanDesc scan;
|
|
||||||
ScanKeyData key;
|
|
||||||
HeapTuple tup;
|
|
||||||
bool isnull;
|
|
||||||
Datum datum;
|
Datum datum;
|
||||||
Query *query = NULL;
|
Datum values[Natts_pg_ivm_immv];
|
||||||
|
HeapTuple newtup = NULL;
|
||||||
|
HeapTuple tup;
|
||||||
IntoClause *into;
|
IntoClause *into;
|
||||||
ParseState *pstate = NULL;
|
ParseState *pstate = NULL;
|
||||||
CreateTableAsStmt *stmt;
|
Query *query = NULL;
|
||||||
const char *querystring;
|
Relation pgIvmImmv = table_open(PgIvmImmvRelationId(), AccessShareLock);
|
||||||
const char *relname;
|
ScanKeyData key;
|
||||||
const char *querytree;
|
SysScanDesc scan;
|
||||||
|
TupleDesc tupdesc = RelationGetDescr(pgIvmImmv);
|
||||||
|
|
||||||
Datum values[Natts_pg_ivm_immv];
|
bool isnull;
|
||||||
bool nulls[Natts_pg_ivm_immv];
|
bool nulls[Natts_pg_ivm_immv];
|
||||||
bool replaces[Natts_pg_ivm_immv];
|
bool replaces[Natts_pg_ivm_immv];
|
||||||
HeapTuple newtup = NULL;
|
const char *querystring;
|
||||||
|
const char *querytree;
|
||||||
|
const char *relname;
|
||||||
|
|
||||||
|
/* Scan pg_ivm_immv for the given IMMV entry. */
|
||||||
ScanKeyInit(&key,
|
ScanKeyInit(&key,
|
||||||
Anum_pg_ivm_immv_immvrelid,
|
Anum_pg_ivm_immv_immvrelid,
|
||||||
BTEqualStrategyNumber, F_OIDEQ,
|
BTEqualStrategyNumber, F_OIDEQ,
|
||||||
|
|
@ -763,10 +776,12 @@ recreate_immv_query(Relation matviewRel)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Read the query string column. */
|
||||||
datum = heap_getattr(tup, Anum_pg_ivm_immv_querystring, tupdesc, &isnull);
|
datum = heap_getattr(tup, Anum_pg_ivm_immv_querystring, tupdesc, &isnull);
|
||||||
Assert(!isnull);
|
Assert(!isnull);
|
||||||
querystring = TextDatumGetCString(datum);
|
querystring = TextDatumGetCString(datum);
|
||||||
|
|
||||||
|
/* Parse the query string using the same logic as create_immv. */
|
||||||
relname = psprintf("%s.%s",
|
relname = psprintf("%s.%s",
|
||||||
get_namespace_name(get_rel_namespace(matviewRel->rd_id)),
|
get_namespace_name(get_rel_namespace(matviewRel->rd_id)),
|
||||||
get_rel_name(matviewRel->rd_id));
|
get_rel_name(matviewRel->rd_id));
|
||||||
|
|
@ -779,6 +794,7 @@ recreate_immv_query(Relation matviewRel)
|
||||||
query = rewriteQueryForIMMV(query, into->colNames);
|
query = rewriteQueryForIMMV(query, into->colNames);
|
||||||
querytree = nodeToString((Node *) query);
|
querytree = nodeToString((Node *) query);
|
||||||
|
|
||||||
|
/* Update the pg_ivm_immv tuple with the new query tree. */
|
||||||
memset(values, 0, sizeof(values));
|
memset(values, 0, sizeof(values));
|
||||||
memset(nulls, 0, sizeof(nulls));
|
memset(nulls, 0, sizeof(nulls));
|
||||||
memset(replaces, 0, sizeof(replaces));
|
memset(replaces, 0, sizeof(replaces));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue