Skip to content

Change temp table name used to IMMV to some less frequent sequence of…#581

Merged
my-ship-it merged 2 commits into
apache:mainfrom
reshke:temp_table
Aug 23, 2024
Merged

Change temp table name used to IMMV to some less frequent sequence of…#581
my-ship-it merged 2 commits into
apache:mainfrom
reshke:temp_table

Conversation

@reshke

@reshke reshke commented Aug 20, 2024

Copy link
Copy Markdown
Contributor

Currently, if user run CREATE TEMP TABLE t(); in their session, IVM will fail. Change its name with generated one, which has a little probability to cause problems.

Also, i added some debug logging and CBDB_IVM_FIXME comment that I feel needed.

@my-ship-it
my-ship-it requested a review from yjhjstz August 20, 2024 10:29
@yjhjstz

yjhjstz commented Aug 20, 2024

Copy link
Copy Markdown
Member

think about schema to solve this ?

@reshke

reshke commented Aug 20, 2024

Copy link
Copy Markdown
Contributor Author

think about schema to solve this ?

Temporary tables exist in a special schema, so a schema name cannot be given when creating a temporary table.[1]

[1] https://www.postgresql.org/docs/current/sql-createtable.html

reshke=# create temp table ex.t();
ERROR:  cannot create temporary relation in non-temporary schema
LINE 1: create temp table ex.t();
                          ^

@yjhjstz

yjhjstz commented Aug 20, 2024

Copy link
Copy Markdown
Member

think about schema to solve this ?

Temporary tables exist in a special schema, so a schema name cannot be given when creating a temporary table.[1]

[1] https://www.postgresql.org/docs/current/sql-createtable.html

reshke=# create temp table ex.t();
ERROR:  cannot create temporary relation in non-temporary schema
LINE 1: create temp table ex.t();
                          ^

I may found a way out:
refer to refresh_by_match_merge, make_new_heap of RELPERSISTENCE_TEMP tablespace, that will not confilct.

@reshke

reshke commented Aug 21, 2024

Copy link
Copy Markdown
Contributor Author

think about schema to solve this ?

Temporary tables exist in a special schema, so a schema name cannot be given when creating a temporary table.[1]
[1] https://www.postgresql.org/docs/current/sql-createtable.html

reshke=# create temp table ex.t();
ERROR:  cannot create temporary relation in non-temporary schema
LINE 1: create temp table ex.t();
                          ^

I may found a way out: refer to refresh_by_match_merge, make_new_heap of RELPERSISTENCE_TEMP tablespace, that will not confilct.

I'm not quite following you suggestion here... First of all, there are no RELPERSISTENCE_TEMP usage inside refresh_by_match_merge? Did you mean ExecRefreshMatView func? If so, it uses RELPERSISTENCE_TEMP, yes. It assigns this value to relpersistence under if-concurrent condition.

https://github.com/cloudberrydb/cloudberrydb/blob/dccc518bea74302c3aebbf446a6fa47f8510c12c/src/backend/commands/matview.c#L502-L506

Then it passes this variable to make_new_heap.

https://github.com/cloudberrydb/cloudberrydb/blob/dccc518bea74302c3aebbf446a6fa47f8510c12c/src/backend/commands/matview.c#L586-L589

In this function we have following:


	if (relpersistence == RELPERSISTENCE_TEMP)
		namespaceid = LookupCreationNamespace("pg_temp");
	else
		namespaceid = RelationGetNamespace(OldHeap);

https://github.com/cloudberrydb/cloudberrydb/blob/dccc518bea74302c3aebbf446a6fa47f8510c12c/src/backend/commands/cluster.c#L756-L759

So, this is the same as CREATE TEMP TABLE $name.

Do I miss something?

@yjhjstz

yjhjstz commented Aug 21, 2024

Copy link
Copy Markdown
Member

yes, in ExecRefreshMatView, or make_new_heap conflict, we may need use tuplestore .

@yjhjstz yjhjstz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@my-ship-it
my-ship-it merged commit 8323a4c into apache:main Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants