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

Commit8e24c01

Browse files
committed
tiny hack: bind custom data to EState using MemoryContext callbacks (estate_mod_data), refactoring, check that partition exists when INSERTing
1 parent348c507 commit8e24c01

File tree

4 files changed

+227
-139
lines changed

4 files changed

+227
-139
lines changed

‎expected/pg_pathman.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ SELECT pathman.disable_auto('test.range_rel');
12671267
(1 row)
12681268

12691269
INSERT INTO test.range_rel (dt) VALUES ('2015-06-01');
1270-
ERROR:There isno suitable partition for key 'Mon Jun 01 00:00:00 2015'
1270+
ERROR: no suitable partition for key 'Mon Jun 01 00:00:00 2015'
12711271
SELECT pathman.enable_auto('test.range_rel');
12721272
enable_auto
12731273
-------------

‎src/copy_stmt_hooking.c

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ static uint64 PathmanCopyFrom(CopyState cstate,
3838
Relationparent_rel,
3939
List*range_table,
4040
boolold_protocol);
41-
staticResultRelInfoHolder*select_partition_for_copy(constPartRelationInfo*prel,
42-
ResultPartsStorage*parts_storage,
43-
Datumvalue,EState*estate);
4441

4542

4643
/*
@@ -376,7 +373,7 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
376373
/* Initialize ResultPartsStorage */
377374
init_result_parts_storage(&parts_storage,estate, false,
378375
ResultPartsStorageStandard,
379-
check_acl_for_partition,NULL);
376+
NULL,NULL);
380377
parts_storage.saved_rel_info=parent_result_rel;
381378

382379
/* Set up a tuple slot too */
@@ -418,16 +415,19 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
418415
/* Fetch PartRelationInfo for parent relation */
419416
prel=get_pathman_relation_info(RelationGetRelid(parent_rel));
420417

421-
/* Switch intoits memory context */
418+
/* Switch intoper tuple memory context */
422419
MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
423420

424421
if (!NextCopyFrom(cstate,econtext,values,nulls,&tuple_oid))
425422
break;
426423

424+
if (nulls[prel->attnum-1])
425+
elog(ERROR,ERR_PART_ATTR_NULL);
426+
427427
/* Search for a matching partition */
428-
rri_holder_child=select_partition_for_copy(prel,&parts_storage,
429-
values[prel->attnum-1],
430-
estate);
428+
rri_holder_child=select_partition_for_insert(prel,&parts_storage,
429+
values[prel->attnum-1],
430+
estate, false);
431431
child_result_rel=rri_holder_child->result_rel_info;
432432
estate->es_result_relation_info=child_result_rel;
433433

@@ -477,8 +477,7 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
477477

478478
if (child_result_rel->ri_NumIndices>0)
479479
recheckIndexes=ExecInsertIndexTuples(slot,&(tuple->t_self),
480-
estate, false,NULL,
481-
NIL);
480+
estate, false,NULL,NIL);
482481

483482
/* AFTER ROW INSERT Triggers */
484483
ExecARInsertTriggers(estate,child_result_rel,tuple,
@@ -522,39 +521,3 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
522521

523522
returnprocessed;
524523
}
525-
526-
/*
527-
* Smart wrapper for scan_result_parts_storage().
528-
*/
529-
staticResultRelInfoHolder*
530-
select_partition_for_copy(constPartRelationInfo*prel,
531-
ResultPartsStorage*parts_storage,
532-
Datumvalue,EState*estate)
533-
{
534-
ExprContext*econtext;
535-
ResultRelInfoHolder*rri_holder;
536-
Oidselected_partid=InvalidOid;
537-
Oid*parts;
538-
intnparts;
539-
540-
econtext=GetPerTupleExprContext(estate);
541-
542-
/* Search for matching partitions using partitioned column */
543-
parts=find_partitions_for_value(value,prel,econtext,&nparts);
544-
545-
if (nparts>1)
546-
elog(ERROR,"PATHMAN COPY selected more than one partition");
547-
elseif (nparts==0)
548-
elog(ERROR,
549-
"There is no suitable partition for key '%s'",
550-
datum_to_cstring(value,prel->atttype));
551-
else
552-
selected_partid=parts[0];
553-
554-
/* Replace parent table with a suitable partition */
555-
MemoryContextSwitchTo(estate->es_query_cxt);
556-
rri_holder=scan_result_parts_storage(selected_partid,parts_storage);
557-
MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
558-
559-
returnrri_holder;
560-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp