Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit102bb31

Browse files
committed
Fix COPY and 'handle_modification_query
1 parentdf85277 commit102bb31

File tree

3 files changed

+67
-18
lines changed

3 files changed

+67
-18
lines changed

‎src/partition_creation.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,27 @@ text_to_regprocedure(text *proc_signature)
16831683
returnDatumGetObjectId(result);
16841684
}
16851685

1686+
/*
1687+
* Checks that columns are from partitioning relation
1688+
* Maybe there will be more checks later.
1689+
*/
1690+
staticbool
1691+
validate_part_expression(Node*node,void*context)
1692+
{
1693+
if (node==NULL)
1694+
return false;
1695+
1696+
if (IsA(node,Var))
1697+
{
1698+
Var*var= (Var*)node;
1699+
if (var->varno!=1)
1700+
elog(ERROR,"Columns used in expression should only be related"
1701+
" with partitioning relation");
1702+
return false;
1703+
}
1704+
returnexpression_tree_walker(node,validate_part_expression,context);
1705+
}
1706+
16861707
/* Wraps expression by SELECT query and returns parsed tree */
16871708
Node*
16881709
get_raw_expression(Oidrelid,constchar*expr,char**query_string_out,
@@ -1787,11 +1808,12 @@ get_part_expression_info(Oid relid, const char *expr_string,
17871808
target_entry=lfirst(list_head(plan->planTree->targetlist));
17881809
expr_node= (Node*)target_entry->expr;
17891810
expr_node=eval_const_expressions(NULL,expr_node);
1811+
validate_part_expression(expr_node,NULL);
17901812
out_string=nodeToString(expr_node);
17911813

17921814
MemoryContextSwitchTo(oldcontext);
17931815

1794-
/*Convert expressiontostring andreturn it as datum */
1816+
/*Save expression stringas datumandfree memory from planning stage */
17951817
expr_info->expr_datum=CStringGetTextDatum(out_string);
17961818
MemoryContextReset(pathman_parse_context);
17971819

‎src/planner_tree_modification.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include"nodes_common.h"
1616
#include"partition_filter.h"
1717
#include"planner_tree_modification.h"
18+
#include"rewrite/rewriteManip.h"
1819

1920
#include"miscadmin.h"
2021
#include"optimizer/clauses.h"
@@ -244,6 +245,7 @@ handle_modification_query(Query *parse)
244245
Expr*expr;
245246
WalkerContextcontext;
246247
Indexresult_rel;
248+
Node*prel_expr;
247249

248250
/* Fetch index of result relation */
249251
result_rel=parse->resultRelation;
@@ -274,8 +276,13 @@ handle_modification_query(Query *parse)
274276
/* Exit if there's no expr (no use) */
275277
if (!expr)return;
276278

279+
/* Prepare partitioning expression */
280+
prel_expr=copyObject(prel->expr);
281+
if (result_rel!=1)
282+
ChangeVarNodes(prel_expr,1,result_rel,0);
283+
277284
/* Parse syntax tree and extract partition ranges */
278-
InitWalkerContext(&context,result_rel,prel,NULL, false);
285+
InitWalkerContext(&context,prel_expr,prel,NULL, false);
279286
wrap=walk_expr_tree(expr,&context);
280287

281288
ranges=irange_list_intersection(ranges,wrap->rangeset);

‎src/utility_stmt_hooking.c

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
478478
TupleTableSlot*myslot;
479479
MemoryContextoldcontext=CurrentMemoryContext;
480480

481+
Node*expr=NULL;
482+
ExprState*expr_state=NULL;
483+
481484
uint64processed=0;
482485

483486

@@ -525,9 +528,13 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
525528

526529
for (;;)
527530
{
528-
TupleTableSlot*slot;
529-
boolskip_tuple;
531+
TupleTableSlot*slot,
532+
*tmp_slot;
533+
ExprDoneConditemIsDone;
534+
boolskip_tuple,
535+
isnull;
530536
Oidtuple_oid=InvalidOid;
537+
Datumvalue;
531538

532539
constPartRelationInfo*prel;
533540
ResultRelInfoHolder*rri_holder;
@@ -540,28 +547,45 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
540547
/* Fetch PartRelationInfo for parent relation */
541548
prel=get_pathman_relation_info(RelationGetRelid(parent_rel));
542549

543-
/* Switch into per tuple memory context */
544-
MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
550+
/* Initialize expression and expression state */
551+
if (expr==NULL)
552+
{
553+
expr=copyObject(prel->expr);
554+
expr_state=ExecInitExpr((Expr*)expr,NULL);
555+
}
545556

546557
if (!NextCopyFrom(cstate,econtext,values,nulls,&tuple_oid))
547558
break;
548559

549-
/* FIX this
550-
if (nulls[prel->attnum - 1])
560+
/* And now we can form the input tuple. */
561+
tuple=heap_form_tuple(tupDesc,values,nulls);
562+
563+
/* Place tuple in tuple slot --- but slot shouldn't free it */
564+
slot=myslot;
565+
ExecStoreTuple(tuple,slot,InvalidBuffer, false);
566+
567+
/* Switch into per tuple memory context */
568+
MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
569+
570+
/* Execute expression */
571+
tmp_slot=econtext->ecxt_scantuple;
572+
econtext->ecxt_scantuple=slot;
573+
value=ExecEvalExpr(expr_state,econtext,&isnull,&itemIsDone);
574+
econtext->ecxt_scantuple=tmp_slot;
575+
576+
if (isnull)
551577
elog(ERROR,ERR_PART_ATTR_NULL);
552-
*/
578+
579+
if (itemIsDone!=ExprSingleResult)
580+
elog(ERROR,ERR_PART_ATTR_MULTIPLE_RESULTS);
553581

554582
/* Search for a matching partition */
555-
/* FIX here, attnum */
556-
rri_holder=select_partition_for_insert(values[/* here */1],
583+
rri_holder=select_partition_for_insert(value,
557584
prel->atttype,prel,
558585
&parts_storage,estate);
559586
child_result_rel=rri_holder->result_rel_info;
560587
estate->es_result_relation_info=child_result_rel;
561588

562-
/* And now we can form the input tuple. */
563-
tuple=heap_form_tuple(tupDesc,values,nulls);
564-
565589
/* If there's a transform map, rebuild the tuple */
566590
if (rri_holder->tuple_map)
567591
{
@@ -585,10 +609,6 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
585609
/* Triggers and stuff need to be invoked in query context. */
586610
MemoryContextSwitchTo(oldcontext);
587611

588-
/* Place tuple in tuple slot --- but slot shouldn't free it */
589-
slot=myslot;
590-
ExecStoreTuple(tuple,slot,InvalidBuffer, false);
591-
592612
skip_tuple= false;
593613

594614
/* BEFORE ROW INSERT Triggers */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp