public inbox for [email protected]
help / color / mirror / Atom feed[PATCH v18 09/18] tableam: slotify CREATE TABLE AS and CREATE MATERIALIZED VIEW.
5+ messages / 4 participants
[nested] [flat]
* [PATCH v18 09/18] tableam: slotify CREATE TABLE AS and CREATE MATERIALIZED VIEW.
@ 2019-01-20 07:22 Andres Freund <[email protected]>
0 siblings, 0 replies; 5+ messages in thread
From: Andres Freund @ 2019-01-20 07:22 UTC (permalink / raw)
Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:
---
src/backend/commands/createas.c | 26 ++++++++++++++++----------
src/backend/commands/matview.c | 26 ++++++++++++++------------
2 files changed, 30 insertions(+), 22 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 55f61854614..31b8691c988 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -27,6 +27,7 @@
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/htup_details.h"
+#include "access/tableam.h"
#include "access/sysattr.h"
#include "access/tableam.h"
#include "access/xact.h"
@@ -61,7 +62,8 @@ typedef struct
ObjectAddress reladdr; /* address of rel, for ExecCreateTableAs */
CommandId output_cid; /* cmin to insert in output tuples */
int hi_options; /* heap_insert performance options */
- BulkInsertState bistate; /* bulk insert state */
+ BulkInsertState bistate; /* bulk insert state */
+ TupleTableSlot *slot;
} DR_intorel;
/* utility functions for CTAS definition creation */
@@ -553,6 +555,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
myState->rel = intoRelationDesc;
myState->reladdr = intoRelationAddr;
myState->output_cid = GetCurrentCommandId(true);
+ myState->slot = table_slot_create(intoRelationDesc, NULL);
/*
* We can skip WAL-logging the insertions, unless PITR or streaming
@@ -573,19 +576,21 @@ static bool
intorel_receive(TupleTableSlot *slot, DestReceiver *self)
{
DR_intorel *myState = (DR_intorel *) self;
- HeapTuple tuple;
/*
- * get the heap tuple out of the tuple table slot, making sure we have a
- * writable copy
+ * Ensure input tuple is the right format for the target relation.
*/
- tuple = ExecCopySlotHeapTuple(slot);
+ if (slot->tts_ops != myState->slot->tts_ops)
+ {
+ ExecCopySlot(myState->slot, slot);
+ slot = myState->slot;
+ }
- heap_insert(myState->rel,
- tuple,
- myState->output_cid,
- myState->hi_options,
- myState->bistate);
+ table_insert(myState->rel,
+ slot,
+ myState->output_cid,
+ myState->hi_options,
+ myState->bistate);
/* We know this is a newly created relation, so there are no indexes */
@@ -600,6 +605,7 @@ intorel_shutdown(DestReceiver *self)
{
DR_intorel *myState = (DR_intorel *) self;
+ ExecDropSingleTupleTableSlot(myState->slot);
FreeBulkInsertState(myState->bistate);
table_finish_bulk_insert(myState->rel, myState->hi_options);
diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c
index 62b76cfd358..e291ad0c547 100644
--- a/src/backend/commands/matview.c
+++ b/src/backend/commands/matview.c
@@ -56,6 +56,7 @@ typedef struct
CommandId output_cid; /* cmin to insert in output tuples */
int hi_options; /* heap_insert performance options */
BulkInsertState bistate; /* bulk insert state */
+ TupleTableSlot *slot;
} DR_transientrel;
static int matview_maintenance_depth = 0;
@@ -457,6 +458,7 @@ transientrel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
*/
myState->transientrel = transientrel;
myState->output_cid = GetCurrentCommandId(true);
+ myState->slot = table_slot_create(transientrel, NULL);
/*
* We can skip WAL-logging the insertions, unless PITR or streaming
@@ -478,25 +480,24 @@ static bool
transientrel_receive(TupleTableSlot *slot, DestReceiver *self)
{
DR_transientrel *myState = (DR_transientrel *) self;
- HeapTuple tuple;
/*
- * get the heap tuple out of the tuple table slot, making sure we have a
- * writable copy
+ * Ensure input tuple is the right format for the target relation.
*/
- tuple = ExecCopySlotHeapTuple(slot);
+ if (slot->tts_ops != myState->slot->tts_ops)
+ {
+ ExecCopySlot(myState->slot, slot);
+ slot = myState->slot;
+ }
- heap_insert(myState->transientrel,
- tuple,
- myState->output_cid,
- myState->hi_options,
- myState->bistate);
+ table_insert(myState->transientrel,
+ slot,
+ myState->output_cid,
+ myState->hi_options,
+ myState->bistate);
/* We know this is a newly created relation, so there are no indexes */
- /* Free the copied tuple. */
- heap_freetuple(tuple);
-
return true;
}
@@ -508,6 +509,7 @@ transientrel_shutdown(DestReceiver *self)
{
DR_transientrel *myState = (DR_transientrel *) self;
+ ExecDropSingleTupleTableSlot(myState->slot);
FreeBulkInsertState(myState->bistate);
table_finish_bulk_insert(myState->transientrel, myState->hi_options);
--
2.21.0.dirty
--yvn3crbc4qf4vymf
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v18-0010-tableam-index-builds.patch"
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: bug fix and documentation improvement about vacuumdb
@ 2023-09-24 08:22 Kuwamura Masaki <[email protected]>
0 siblings, 1 reply; 5+ messages in thread
From: Kuwamura Masaki @ 2023-09-24 08:22 UTC (permalink / raw)
To: Nathan Bossart <[email protected]>; +Cc: Daniel Gustafsson <[email protected]>; Kyotaro Horiguchi <[email protected]>; PostgreSQL Hackers <[email protected]>
LGTM too!
>> a bit to make the diff smaller,
I couldn't think from that perspective. Thanks for your update, Daniel-san.
Masaki Kuwamura
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: bug fix and documentation improvement about vacuumdb
@ 2023-09-25 14:18 Daniel Gustafsson <[email protected]>
parent: Kuwamura Masaki <[email protected]>
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Gustafsson @ 2023-09-25 14:18 UTC (permalink / raw)
To: Kuwamura Masaki <[email protected]>; +Cc: Nathan Bossart <[email protected]>; Kyotaro Horiguchi <[email protected]>; PostgreSQL Hackers <[email protected]>
> On 24 Sep 2023, at 10:22, Kuwamura Masaki <[email protected]> wrote:
>
> LGTM too!
I've applied this down to v16 now, thanks for the submission!
--
Daniel Gustafsson
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: bug fix and documentation improvement about vacuumdb
@ 2023-09-26 01:22 Kuwamura Masaki <[email protected]>
parent: Daniel Gustafsson <[email protected]>
0 siblings, 0 replies; 5+ messages in thread
From: Kuwamura Masaki @ 2023-09-26 01:22 UTC (permalink / raw)
To: Daniel Gustafsson <[email protected]>; +Cc: Nathan Bossart <[email protected]>; Kyotaro Horiguchi <[email protected]>; PostgreSQL Hackers <[email protected]>
>
> I've applied this down to v16 now, thanks for the submission!
>
Thanks for pushing!
Masaki Kuwamura
^ permalink raw reply [nested|flat] 5+ messages in thread
* [PATCH v15 3/8] Row pattern recognition patch (rewriter).
@ 2024-03-28 10:30 Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 5+ messages in thread
From: Tatsuo Ishii @ 2024-03-28 10:30 UTC (permalink / raw)
---
src/backend/utils/adt/ruleutils.c | 103 ++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index a51717e36c..51ba9fc7b4 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -426,6 +426,10 @@ static void get_rule_groupingset(GroupingSet *gset, List *targetlist,
bool omit_parens, deparse_context *context);
static void get_rule_orderby(List *orderList, List *targetList,
bool force_colno, deparse_context *context);
+static void get_rule_pattern(List *patternVariable, List *patternRegexp,
+ bool force_colno, deparse_context *context);
+static void get_rule_define(List *defineClause, List *patternVariables,
+ bool force_colno, deparse_context *context);
static void get_rule_windowclause(Query *query, deparse_context *context);
static void get_rule_windowspec(WindowClause *wc, List *targetList,
deparse_context *context);
@@ -6480,6 +6484,67 @@ get_rule_orderby(List *orderList, List *targetList,
}
}
+/*
+ * Display a PATTERN clause.
+ */
+static void
+get_rule_pattern(List *patternVariable, List *patternRegexp,
+ bool force_colno, deparse_context *context)
+{
+ StringInfo buf = context->buf;
+ const char *sep;
+ ListCell *lc_var,
+ *lc_reg = list_head(patternRegexp);
+
+ sep = "";
+ appendStringInfoChar(buf, '(');
+ foreach(lc_var, patternVariable)
+ {
+ char *variable = strVal((String *) lfirst(lc_var));
+ char *regexp = NULL;
+
+ if (lc_reg != NULL)
+ {
+ regexp = strVal((String *) lfirst(lc_reg));
+
+ lc_reg = lnext(patternRegexp, lc_reg);
+ }
+
+ appendStringInfo(buf, "%s%s", sep, variable);
+ if (regexp !=NULL)
+ appendStringInfoString(buf, regexp);
+
+ sep = " ";
+ }
+ appendStringInfoChar(buf, ')');
+}
+
+/*
+ * Display a DEFINE clause.
+ */
+static void
+get_rule_define(List *defineClause, List *patternVariables,
+ bool force_colno, deparse_context *context)
+{
+ StringInfo buf = context->buf;
+ const char *sep;
+ ListCell *lc_var,
+ *lc_def;
+
+ sep = " ";
+ Assert(list_length(patternVariables) == list_length(defineClause));
+
+ forboth(lc_var, patternVariables, lc_def, defineClause)
+ {
+ char *varName = strVal(lfirst(lc_var));
+ TargetEntry *te = (TargetEntry *) lfirst(lc_def);
+
+ appendStringInfo(buf, "%s%s AS ", sep, varName);
+ get_rule_expr((Node *) te->expr, context, false);
+ sep = ",\n ";
+ }
+}
+
/*
* Display a WINDOW clause.
*
@@ -6617,6 +6682,44 @@ get_rule_windowspec(WindowClause *wc, List *targetList,
appendStringInfoString(buf, "EXCLUDE GROUP ");
else if (wc->frameOptions & FRAMEOPTION_EXCLUDE_TIES)
appendStringInfoString(buf, "EXCLUDE TIES ");
+ /* RPR */
+ if (wc->rpSkipTo == ST_NEXT_ROW)
+ appendStringInfoString(buf,
+ "\n AFTER MATCH SKIP TO NEXT ROW ");
+ else if (wc->rpSkipTo == ST_PAST_LAST_ROW)
+ appendStringInfoString(buf,
+ "\n AFTER MATCH SKIP PAST LAST ROW ");
+ else if (wc->rpSkipTo == ST_FIRST_VARIABLE)
+ appendStringInfo(buf,
+ "\n AFTER MATCH SKIP TO FIRST %s ",
+ wc->rpSkipVariable);
+ else if (wc->rpSkipTo == ST_LAST_VARIABLE)
+ appendStringInfo(buf,
+ "\n AFTER MATCH SKIP TO LAST %s ",
+ wc->rpSkipVariable);
+ else if (wc->rpSkipTo == ST_VARIABLE)
+ appendStringInfo(buf,
+ "\n AFTER MATCH SKIP TO %s ",
+ wc->rpSkipVariable);
+
+ if (wc->initial)
+ appendStringInfoString(buf, "\n INITIAL");
+
+ if (wc->patternVariable)
+ {
+ appendStringInfoString(buf, "\n PATTERN ");
+ get_rule_pattern(wc->patternVariable, wc->patternRegexp,
+ false, context);
+ }
+
+ if (wc->defineClause)
+ {
+ appendStringInfoString(buf, "\n DEFINE\n");
+ get_rule_define(wc->defineClause, wc->patternVariable,
+ false, context);
+ appendStringInfoChar(buf, ' ');
+ }
+
/* we will now have a trailing space; remove it */
buf->len--;
}
--
2.25.1
----Next_Part(Thu_Mar_28_19_59_25_2024_076)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="v15-0004-Row-pattern-recognition-patch-planner.patch"
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2024-03-28 10:30 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-01-20 07:22 [PATCH v18 09/18] tableam: slotify CREATE TABLE AS and CREATE MATERIALIZED VIEW. Andres Freund <[email protected]>
2023-09-24 08:22 Re: bug fix and documentation improvement about vacuumdb Kuwamura Masaki <[email protected]>
2023-09-25 14:18 ` Re: bug fix and documentation improvement about vacuumdb Daniel Gustafsson <[email protected]>
2023-09-26 01:22 ` Re: bug fix and documentation improvement about vacuumdb Kuwamura Masaki <[email protected]>
2024-03-28 10:30 [PATCH v15 3/8] Row pattern recognition patch (rewriter). Tatsuo Ishii <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox