Adding tests for inheritance trees with temporary tables

Started by Michael Paquierover 7 years ago6 messages
#1Michael Paquier
michael@paquier.xyz
1 attachment(s)

Hi all,

While look at the handling of temporary relations with partition trees,
I have noticed that there are no tests for inheritance trees with temp
tables. This has been mentioned here:
/messages/by-id/20180618060200.GG3721@paquier.xyz

Attached is a patch to close the gap. That's of course not v11
material, so I am parking this patch into the next CF.

Thanks,
--
Michael

Attachments:

inherit-temp-tests.patchtext/x-diff; charset=us-asciiDownload
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index b2b912ed5c..9b1312a0ca 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -1710,6 +1710,51 @@ select * from cnullparent where f1 = 2;
 drop table cnullparent cascade;
 NOTICE:  drop cascades to table cnullchild
 --
+-- Check use of temprary tables with inheritance trees
+--
+create table inh_perm_parent (a1 int);
+create temp table inh_temp_parent (a1 int);
+create temp table inh_temp_child (a1 int) inherits (inh_perm_parent); -- ok
+NOTICE:  merging column "a1" with inherited definition
+create table inh_perm_child (a1 int) inherits (inh_temp_parent); -- error
+ERROR:  cannot inherit from temporary relation "inh_temp_parent"
+create temp table inh_temp_child_2 (a1 int) inherits (inh_temp_parent); -- ok
+NOTICE:  merging column "a1" with inherited definition
+insert into inh_perm_parent values (1);
+insert into inh_temp_parent values (2);
+insert into inh_temp_child values (3);
+insert into inh_temp_child_2 values (4);
+select * from inh_perm_parent;
+ a1 
+----
+  1
+  3
+(2 rows)
+
+select * from inh_temp_parent;
+ a1 
+----
+  2
+  4
+(2 rows)
+
+select * from inh_temp_child;
+ a1 
+----
+  3
+(1 row)
+
+select * from inh_temp_child_2;
+ a1 
+----
+  4
+(1 row)
+
+drop table inh_perm_parent cascade;
+NOTICE:  drop cascades to table inh_temp_child
+drop table inh_temp_parent cascade;
+NOTICE:  drop cascades to table inh_temp_child_2
+--
 -- Check that constraint exclusion works correctly with partitions using
 -- implicit constraints generated from the partition bound information.
 --
diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql
index 5a48376fc0..2c3e35583a 100644
--- a/src/test/regress/sql/inherit.sql
+++ b/src/test/regress/sql/inherit.sql
@@ -635,6 +635,25 @@ select * from cnullparent;
 select * from cnullparent where f1 = 2;
 drop table cnullparent cascade;
 
+--
+-- Check use of temprary tables with inheritance trees
+--
+create table inh_perm_parent (a1 int);
+create temp table inh_temp_parent (a1 int);
+create temp table inh_temp_child (a1 int) inherits (inh_perm_parent); -- ok
+create table inh_perm_child (a1 int) inherits (inh_temp_parent); -- error
+create temp table inh_temp_child_2 (a1 int) inherits (inh_temp_parent); -- ok
+insert into inh_perm_parent values (1);
+insert into inh_temp_parent values (2);
+insert into inh_temp_child values (3);
+insert into inh_temp_child_2 values (4);
+select * from inh_perm_parent;
+select * from inh_temp_parent;
+select * from inh_temp_child;
+select * from inh_temp_child_2;
+drop table inh_perm_parent cascade;
+drop table inh_temp_parent cascade;
+
 --
 -- Check that constraint exclusion works correctly with partitions using
 -- implicit constraints generated from the partition bound information.
#2Ashutosh Bapat
ashutosh.bapat@enterprisedb.com
In reply to: Michael Paquier (#1)
Re: Adding tests for inheritance trees with temporary tables

Thanks. Some review comments here.

+create table inh_perm_parent (a1 int);
+create temp table inh_temp_parent (a1 int);
+create temp table inh_temp_child (a1 int) inherits (inh_perm_parent); -- ok
+NOTICE:  merging column "a1" with inherited definition

You could actually avoid this notice by changing create table statement like
create temp table inh_temp_child () inherits (inh_perm_parent);

+create table inh_perm_child (a1 int) inherits (inh_temp_parent); -- error
+ERROR:  cannot inherit from temporary relation "inh_temp_parent"
+create temp table inh_temp_child_2 (a1 int) inherits (inh_temp_parent); -- ok
+NOTICE:  merging column "a1" with inherited definition

Same suggestion as above.

+insert into inh_perm_parent values (1);
+insert into inh_temp_parent values (2);
+insert into inh_temp_child values (3);
+insert into inh_temp_child_2 values (4);
+select * from inh_perm_parent;
+ a1
+----
+  1
+  3
+(2 rows)
+
+select * from inh_temp_parent;
+ a1
+----
+  2
+  4
+(2 rows)

select tabloid::regclass will also print the name of the table where
the row resides. That will be useful to check where the rows come from
and also to test the inheritance children.

On Tue, Jun 19, 2018 at 7:51 AM, Michael Paquier <michael@paquier.xyz> wrote:

Hi all,

While look at the handling of temporary relations with partition trees,
I have noticed that there are no tests for inheritance trees with temp
tables. This has been mentioned here:
/messages/by-id/20180618060200.GG3721@paquier.xyz

Attached is a patch to close the gap. That's of course not v11
material, so I am parking this patch into the next CF.

Thanks,
--
Michael

--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company

#3Michael Paquier
michael@paquier.xyz
In reply to: Ashutosh Bapat (#2)
1 attachment(s)
Re: Adding tests for inheritance trees with temporary tables

On Tue, Jun 19, 2018 at 01:04:43PM +0530, Ashutosh Bapat wrote:

Thanks. Some review comments here.

Thanks for the review!

+create table inh_perm_parent (a1 int);
+create temp table inh_temp_parent (a1 int);
+create temp table inh_temp_child (a1 int) inherits (inh_perm_parent); -- ok
+NOTICE:  merging column "a1" with inherited definition

You could actually avoid this notice by changing create table statement like
create temp table inh_temp_child () inherits (inh_perm_parent);

Okay, fixed.

select tabloid::regclass will also print the name of the table where
the row resides. That will be useful to check where the rows come from
and also to test the inheritance children.

Good point, I have added those. Except that you meant
tableoid::regclass.
--
Michael

Attachments:

inherit-temp-tests-v2.patchtext/x-diff; charset=us-asciiDownload
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index b2b912ed5c..4f29d9f891 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -1710,6 +1710,37 @@ select * from cnullparent where f1 = 2;
 drop table cnullparent cascade;
 NOTICE:  drop cascades to table cnullchild
 --
+-- Check use of temporary tables with inheritance trees
+--
+create table inh_perm_parent (a1 int);
+create temp table inh_temp_parent (a1 int);
+create temp table inh_temp_child () inherits (inh_perm_parent); -- ok
+create table inh_perm_child () inherits (inh_temp_parent); -- error
+ERROR:  cannot inherit from temporary relation "inh_temp_parent"
+create temp table inh_temp_child_2 () inherits (inh_temp_parent); -- ok
+insert into inh_perm_parent values (1);
+insert into inh_temp_parent values (2);
+insert into inh_temp_child values (3);
+insert into inh_temp_child_2 values (4);
+select tableoid::regclass, a1 from inh_perm_parent;
+    tableoid     | a1 
+-----------------+----
+ inh_perm_parent |  1
+ inh_temp_child  |  3
+(2 rows)
+
+select tableoid::regclass, a1 from inh_temp_parent;
+     tableoid     | a1 
+------------------+----
+ inh_temp_parent  |  2
+ inh_temp_child_2 |  4
+(2 rows)
+
+drop table inh_perm_parent cascade;
+NOTICE:  drop cascades to table inh_temp_child
+drop table inh_temp_parent cascade;
+NOTICE:  drop cascades to table inh_temp_child_2
+--
 -- Check that constraint exclusion works correctly with partitions using
 -- implicit constraints generated from the partition bound information.
 --
diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql
index 5a48376fc0..a6e541d4da 100644
--- a/src/test/regress/sql/inherit.sql
+++ b/src/test/regress/sql/inherit.sql
@@ -635,6 +635,23 @@ select * from cnullparent;
 select * from cnullparent where f1 = 2;
 drop table cnullparent cascade;
 
+--
+-- Check use of temporary tables with inheritance trees
+--
+create table inh_perm_parent (a1 int);
+create temp table inh_temp_parent (a1 int);
+create temp table inh_temp_child () inherits (inh_perm_parent); -- ok
+create table inh_perm_child () inherits (inh_temp_parent); -- error
+create temp table inh_temp_child_2 () inherits (inh_temp_parent); -- ok
+insert into inh_perm_parent values (1);
+insert into inh_temp_parent values (2);
+insert into inh_temp_child values (3);
+insert into inh_temp_child_2 values (4);
+select tableoid::regclass, a1 from inh_perm_parent;
+select tableoid::regclass, a1 from inh_temp_parent;
+drop table inh_perm_parent cascade;
+drop table inh_temp_parent cascade;
+
 --
 -- Check that constraint exclusion works correctly with partitions using
 -- implicit constraints generated from the partition bound information.
#4Ashutosh Bapat
ashutosh.bapat@enterprisedb.com
In reply to: Michael Paquier (#3)
Re: Adding tests for inheritance trees with temporary tables

On Wed, Jun 20, 2018 at 11:39 AM, Michael Paquier <michael@paquier.xyz> wrote:

Good point, I have added those. Except that you meant
tableoid::regclass.

Thanks. I have checked that make check passes with this patch. I have
marked this entry as ready for committer.

--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company

#5Michael Paquier
michael@paquier.xyz
In reply to: Ashutosh Bapat (#4)
Re: Adding tests for inheritance trees with temporary tables

On Wed, Jun 20, 2018 at 06:34:42PM +0530, Ashutosh Bapat wrote:

Thanks. I have checked that make check passes with this patch. I have
marked this entry as ready for committer.

Thanks, Ashutosh.
--
Michael

#6Michael Paquier
michael@paquier.xyz
In reply to: Michael Paquier (#5)
Re: Adding tests for inheritance trees with temporary tables

On Thu, Jun 21, 2018 at 02:37:46PM +0900, Michael Paquier wrote:

On Wed, Jun 20, 2018 at 06:34:42PM +0530, Ashutosh Bapat wrote:

Thanks. I have checked that make check passes with this patch. I have
marked this entry as ready for committer.

Thanks, Ashutosh.

Now pushed. Thanks Ashutosh for the review and the additions!
--
Michael