add materialized view feature to opengauss
This commit is contained in:
@ -48,6 +48,7 @@
|
||||
#include "catalog/pg_statistic.h"
|
||||
#include "catalog/pg_statistic_ext.h"
|
||||
#include "catalog/namespace.h"
|
||||
#include "commands/matview.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "executor/execdebug.h"
|
||||
#include "executor/nodeRecursiveunion.h"
|
||||
@ -1318,7 +1319,7 @@ static void InitPlan(QueryDesc *queryDesc, int eflags)
|
||||
* it is a parameterless subplan (not initplan), we suggest that it be
|
||||
* prepared to handle REWIND efficiently; otherwise there is no need.
|
||||
*/
|
||||
sp_eflags = eflags & EXEC_FLAG_EXPLAIN_ONLY;
|
||||
sp_eflags = eflags & (EXEC_FLAG_EXPLAIN_ONLY | EXEC_FLAG_WITH_NO_DATA);
|
||||
if (bms_is_member(i, plannedstmt->rewindPlanIDs)) {
|
||||
sp_eflags |= EXEC_FLAG_REWIND;
|
||||
}
|
||||
@ -1463,6 +1464,11 @@ void CheckValidResultRel(Relation resultRel, CmdType operation)
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RELKIND_MATVIEW:
|
||||
if (!MatViewIncrementalMaintenanceIsEnabled())
|
||||
ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("cannot change materialized view \"%s\"", RelationGetRelationName(resultRel))));
|
||||
break;
|
||||
case RELKIND_FOREIGN_TABLE:
|
||||
/* Okay only if the FDW supports it */
|
||||
fdwroutine = GetFdwRoutineForRelation(resultRel, false);
|
||||
@ -1536,9 +1542,17 @@ static void CheckValidRowMarkRel(Relation rel, RowMarkType markType)
|
||||
errmsg("cannot lock rows in TOAST relation \"%s\"", RelationGetRelationName(rel))));
|
||||
break;
|
||||
case RELKIND_VIEW:
|
||||
/* Should not get here */
|
||||
/* Allow referencing a matview, but not actual locking clauses */
|
||||
if (markType != ROW_MARK_REFERENCE)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("cannot lock rows in materialized view \"%s\"",
|
||||
RelationGetRelationName(rel))));
|
||||
break;
|
||||
case RELKIND_MATVIEW:
|
||||
/* Should not get here; planner should have used ROW_MARK_COPY */
|
||||
ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("cannot lock rows in view \"%s\"", RelationGetRelationName(rel))));
|
||||
errmsg("cannot lock rows in materialized view \"%s\"", RelationGetRelationName(rel))));
|
||||
break;
|
||||
case RELKIND_FOREIGN_TABLE:
|
||||
/* Should not get here; planner should have used ROW_MARK_COPY */
|
||||
|
||||
@ -1031,7 +1031,7 @@ Relation ExecOpenScanRelation(EState* estate, Index scanrelid)
|
||||
}
|
||||
}
|
||||
|
||||
/* OK, open the relation and acquire lock as needed */
|
||||
/* Open the relation and acquire lock as needed */
|
||||
reloid = getrelid(scanrelid, estate->es_range_table);
|
||||
rel = heap_open(reloid, lockmode);
|
||||
|
||||
|
||||
@ -1866,7 +1866,7 @@ TupleTableSlot* ExecModifyTable(ModifyTableState* node)
|
||||
bool isNull = false;
|
||||
|
||||
relkind = result_rel_info->ri_RelationDesc->rd_rel->relkind;
|
||||
if (relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE) {
|
||||
if (relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE || relkind == RELKIND_MATVIEW) {
|
||||
datum = ExecGetJunkAttribute(slot, junk_filter->jf_junkAttNo, &isNull);
|
||||
/* shouldn't ever get a null result... */
|
||||
if (isNull) {
|
||||
@ -2404,7 +2404,7 @@ ModifyTableState* ExecInitModifyTable(ModifyTable* node, EState* estate, int efl
|
||||
char relkind;
|
||||
|
||||
relkind = result_rel_info->ri_RelationDesc->rd_rel->relkind;
|
||||
if (relkind == RELKIND_RELATION) {
|
||||
if (relkind == RELKIND_RELATION || relkind == RELKIND_MATVIEW) {
|
||||
j->jf_junkAttNo = ExecFindJunkAttribute(j, "ctid");
|
||||
if (!AttributeNumberIsValid(j->jf_junkAttNo)) {
|
||||
ereport(ERROR,
|
||||
|
||||
@ -322,8 +322,7 @@ static AbsTblScanDesc InitBeginScan(SeqScanState* node, Relation current_relatio
|
||||
/* ----------------------------------------------------------------
|
||||
* InitScanRelation
|
||||
*
|
||||
* This does the initialization for scan relations and
|
||||
* subplans of scans.
|
||||
* Set up to access the scan relation.
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
void InitScanRelation(SeqScanState* node, EState* estate)
|
||||
@ -410,6 +409,7 @@ void InitScanRelation(SeqScanState* node, EState* estate)
|
||||
node->ss_currentRelation = current_relation;
|
||||
node->ss_currentScanDesc = current_scan_desc;
|
||||
|
||||
/* and report the scan tuple slot's rowtype */
|
||||
ExecAssignScanType(node, RelationGetDescr(current_relation));
|
||||
}
|
||||
static inline void InitSeqNextMtd(SeqScan* node, SeqScanState* scanstate)
|
||||
|
||||
@ -2069,9 +2069,19 @@ static int _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI, Snapshot sn
|
||||
* SELECT INTO.
|
||||
*/
|
||||
if (IsA(stmt, CreateTableAsStmt)) {
|
||||
Assert(strncmp(completionTag, "SELECT ", 7) == 0);
|
||||
u_sess->SPI_cxt._current->processed = strtoul(completionTag + 7, NULL, 10);
|
||||
if (((CreateTableAsStmt *)stmt)->is_select_into) {
|
||||
CreateTableAsStmt *ctastmt = (CreateTableAsStmt *) stmt;
|
||||
if (strncmp(completionTag, "SELECT ", 7) == 0) {
|
||||
u_sess->SPI_cxt._current->processed = strtoul(completionTag + 7, NULL, 10);
|
||||
} else {
|
||||
/*
|
||||
* Must be an IF NOT EXISTS that did nothing, or a
|
||||
* CREATE ... WITH NO DATA.
|
||||
*/
|
||||
Assert(ctastmt->into->skipData);
|
||||
u_sess->SPI_cxt._current->processed = 0;
|
||||
}
|
||||
|
||||
if (ctastmt->is_select_into) {
|
||||
res = SPI_OK_SELINTO;
|
||||
} else {
|
||||
res = SPI_OK_UTILITY;
|
||||
|
||||
Reference in New Issue
Block a user