diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index eca0be1..1f4229d 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2447,6 +2447,11 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
 	TupleTableSlot **slots = buffer->slots;
 
 	/*
+	 * Make resultRelInfo in estate point to the correct relation.
+	 */
+	estate->es_result_relation_info = resultRelInfo;
+
+	/*
 	 * Print error context information correctly, if one of the operations
 	 * below fail.
 	 */
diff --git a/src/test/regress/input/copy.source b/src/test/regress/input/copy.source
index aefc991..e1d55d6 100644
--- a/src/test/regress/input/copy.source
+++ b/src/test/regress/input/copy.source
@@ -188,3 +188,26 @@ select tableoid::regclass,count(*),sum(a) from parted_copytest
 group by tableoid order by tableoid::regclass::name;
 
 drop table parted_copytest;
+
+-- test copy from into partitioned table with index.
+create table part_tab  (a int primary key, b text) partition by range (a);
+
+create table part_tab_1 partition of part_tab for values from (1) to (2);
+create table part_tab_2 partition of part_tab for values from (2) to (3);
+create table part_tab_3 partition of part_tab for values from (3) to (4);
+
+insert into part_tab values (1,  'str1'), (2, 'str2'), (3, 'str3');
+
+copy (select * from part_tab) to '@abs_builddir@/results/parted_copytest_index.csv';
+
+select * from part_tab where a = 1;
+select * from part_tab where a = 2;
+
+truncate part_tab;
+
+copy part_tab from '@abs_builddir@/results/parted_copytest_index.csv';
+
+select * from part_tab where a = 1;
+select * from part_tab where a = 2;
+
+drop table part_tab;
diff --git a/src/test/regress/output/copy.source b/src/test/regress/output/copy.source
index cf716ae..4275c13 100644
--- a/src/test/regress/output/copy.source
+++ b/src/test/regress/output/copy.source
@@ -148,3 +148,37 @@ group by tableoid order by tableoid::regclass::name;
 (2 rows)
 
 drop table parted_copytest;
+-- test copy from into partitioned table with index.
+create table part_tab  (a int primary key, b text) partition by range (a);
+create table part_tab_1 partition of part_tab for values from (1) to (2);
+create table part_tab_2 partition of part_tab for values from (2) to (3);
+create table part_tab_3 partition of part_tab for values from (3) to (4);
+insert into part_tab values (1,  'str1'), (2, 'str2'), (3, 'str3');
+copy (select * from part_tab) to '@abs_builddir@/results/parted_copytest_index.csv';
+select * from part_tab where a = 1;
+ a |  b   
+---+------
+ 1 | str1
+(1 row)
+
+select * from part_tab where a = 2;
+ a |  b   
+---+------
+ 2 | str2
+(1 row)
+
+truncate part_tab;
+copy part_tab from '@abs_builddir@/results/parted_copytest_index.csv';
+select * from part_tab where a = 1;
+ a |  b   
+---+------
+ 1 | str1
+(1 row)
+
+select * from part_tab where a = 2;
+ a |  b   
+---+------
+ 2 | str2
+(1 row)
+
+drop table part_tab;
