Refactor process utility

This breaks up the handling of process utility statements into a clean
and efficient switch statement with separate functions for each
statement.
This commit is contained in:
Erik Nordström 2017-08-07 13:35:21 +02:00 committed by Erik Nordström
parent 69ac1a37d8
commit a1a28ecf6f

View File

@ -37,24 +37,9 @@ prev_ProcessUtility(Node *parsetree,
} }
} }
/* Hook-intercept for ProcessUtility. Used to set COPY completion tag and */
/* renaming of hypertables. */
static void
timescaledb_ProcessUtility(Node *parsetree,
const char *query_string,
ProcessUtilityContext context,
ParamListInfo params,
DestReceiver *dest,
char *completion_tag)
{
if (!extension_is_loaded())
{
prev_ProcessUtility(parsetree, query_string, context, params, dest, completion_tag);
return;
}
/* Truncate a hypertable */ /* Truncate a hypertable */
if (IsA(parsetree, TruncateStmt)) static void
process_truncate(Node *parsetree)
{ {
TruncateStmt *truncatestmt = (TruncateStmt *) parsetree; TruncateStmt *truncatestmt = (TruncateStmt *) parsetree;
ListCell *cell; ListCell *cell;
@ -76,15 +61,12 @@ timescaledb_ProcessUtility(Node *parsetree,
} }
cache_release(hcache); cache_release(hcache);
} }
}
} }
prev_ProcessUtility((Node *) truncatestmt, query_string, context, params, dest, completion_tag); /* Change the schema of a hypertable */
return; static void
} process_alterobjectschema(Node *parsetree)
/* Change the schema of hypertable */
if (IsA(parsetree, AlterObjectSchemaStmt))
{ {
AlterObjectSchemaStmt *alterstmt = (AlterObjectSchemaStmt *) parsetree; AlterObjectSchemaStmt *alterstmt = (AlterObjectSchemaStmt *) parsetree;
Oid relId = RangeVarGetRelid(alterstmt->relation, NoLock, true); Oid relId = RangeVarGetRelid(alterstmt->relation, NoLock, true);
@ -104,13 +86,11 @@ timescaledb_ProcessUtility(Node *parsetree,
} }
cache_release(hcache); cache_release(hcache);
} }
prev_ProcessUtility((Node *) alterstmt, query_string, context, params, dest, completion_tag);
return;
} }
/* Rename hypertable */ /* Rename hypertable */
if (IsA(parsetree, RenameStmt)) static void
process_rename(Node *parsetree)
{ {
RenameStmt *renamestmt = (RenameStmt *) parsetree; RenameStmt *renamestmt = (RenameStmt *) parsetree;
Oid relid = RangeVarGetRelid(renamestmt->relation, NoLock, true); Oid relid = RangeVarGetRelid(renamestmt->relation, NoLock, true);
@ -130,17 +110,15 @@ timescaledb_ProcessUtility(Node *parsetree,
} }
cache_release(hcache); cache_release(hcache);
} }
prev_ProcessUtility((Node *) renamestmt, query_string, context, params, dest, completion_tag);
return;
} }
if (IsA(parsetree, CopyStmt)) static void
process_copy(Node *parsetree, const char *query_string, char *completion_tag)
{ {
CopyStmt *stmt = (CopyStmt *) parsetree; CopyStmt *stmt = (CopyStmt *) parsetree;
/* /*
* Needed to add the appropriate number of tuples to the completion * Needed to add the appropriate number of tuples to the completion tag
* tag
*/ */
uint64 processed; uint64 processed;
Hypertable *ht = NULL; Hypertable *ht = NULL;
@ -173,10 +151,43 @@ timescaledb_ProcessUtility(Node *parsetree,
if (NULL != hcache) if (NULL != hcache)
cache_release(hcache); cache_release(hcache);
}
/* Hook-intercept for ProcessUtility. Used to set COPY completion tag and */
/* renaming of hypertables. */
static void
timescaledb_ProcessUtility(Node *parsetree,
const char *query_string,
ProcessUtilityContext context,
ParamListInfo params,
DestReceiver *dest,
char *completion_tag)
{
if (!extension_is_loaded())
{
prev_ProcessUtility(parsetree, query_string, context, params, dest, completion_tag);
return; return;
} }
switch (nodeTag(parsetree))
{
case T_TruncateStmt:
process_truncate(parsetree);
break;
case T_AlterObjectSchemaStmt:
process_alterobjectschema(parsetree);
break;
case T_RenameStmt:
process_rename(parsetree);
break;
case T_CopyStmt:
process_copy(parsetree, query_string, completion_tag);
return;
default:
break;
}
prev_ProcessUtility(parsetree, query_string, context, params, dest, completion_tag); prev_ProcessUtility(parsetree, query_string, context, params, dest, completion_tag);
} }