@@ -38,9 +38,6 @@ static uint64 PathmanCopyFrom(CopyState cstate,
3838Relation parent_rel ,
3939List * range_table ,
4040bool old_protocol );
41- static ResultRelInfoHolder * select_partition_for_copy (const PartRelationInfo * prel ,
42- ResultPartsStorage * parts_storage ,
43- Datum value ,EState * estate );
4441
4542
4643/*
@@ -376,7 +373,7 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
376373/* Initialize ResultPartsStorage */
377374init_result_parts_storage (& parts_storage ,estate , false,
378375ResultPartsStorageStandard ,
379- check_acl_for_partition ,NULL );
376+ NULL ,NULL );
380377parts_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 */
419416prel = get_pathman_relation_info (RelationGetRelid (parent_rel ));
420417
421- /* Switch intoits memory context */
418+ /* Switch intoper tuple memory context */
422419MemoryContextSwitchTo (GetPerTupleMemoryContext (estate ));
423420
424421if (!NextCopyFrom (cstate ,econtext ,values ,nulls ,& tuple_oid ))
425422break ;
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 );
431431child_result_rel = rri_holder_child -> result_rel_info ;
432432estate -> es_result_relation_info = child_result_rel ;
433433
@@ -477,8 +477,7 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
477477
478478if (child_result_rel -> ri_NumIndices > 0 )
479479recheckIndexes = ExecInsertIndexTuples (slot ,& (tuple -> t_self ),
480- estate , false,NULL ,
481- NIL );
480+ estate , false,NULL ,NIL );
482481
483482/* AFTER ROW INSERT Triggers */
484483ExecARInsertTriggers (estate ,child_result_rel ,tuple ,
@@ -522,39 +521,3 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
522521
523522return processed ;
524523}
525-
526- /*
527- * Smart wrapper for scan_result_parts_storage().
528- */
529- static ResultRelInfoHolder *
530- select_partition_for_copy (const PartRelationInfo * prel ,
531- ResultPartsStorage * parts_storage ,
532- Datum value ,EState * estate )
533- {
534- ExprContext * econtext ;
535- ResultRelInfoHolder * rri_holder ;
536- Oid selected_partid = InvalidOid ;
537- Oid * parts ;
538- int nparts ;
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- else if (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- return rri_holder ;
560- }