agora inbox for [email protected]
help / color / mirror / Atom feedRemoval of temp tables
333+ messages / 4 participants
[nested] [flat]
* Removal of temp tables
@ 2001-06-14 04:17 Bruce Momjian <[email protected]>
0 siblings, 1 reply; 333+ messages in thread
From: Bruce Momjian @ 2001-06-14 04:17 UTC (permalink / raw)
To: PostgreSQL-patches <[email protected]>
Here is a patch that allows people to delete the pg_temp* tables used as
temp tables. They are left around after a backend crash and the only
way previously to remove them was to start postgres with the -O override
option.
I am wondering if pg_temp tables should even be seen as system tables by
IsSystemRelationName(). We have to call them pg_ so user applications
don't display them, but other than that they aren't like system tables.
Comments?
There are no tests to see if the table is actually in use. I can add
them if people want it.
---------------------------------------------------------------------------
test=> CREATE TEMP TABLE test (x int);
CREATE
test=> \dS
List of relations
Name | Type | Owner
----------------+---------+----------
...
pg_temp.6682.0 | table | postgres
...
test=> DROP TABLE "pg_temp.6682.0";
DROP
--
Bruce Momjian | http://candle.pha.pa.us
[email protected] | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
Index: src/backend/catalog/aclchk.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/aclchk.c,v
retrieving revision 1.50
diff -c -r1.50 aclchk.c
*** src/backend/catalog/aclchk.c 2001/06/09 23:21:54 1.50
--- src/backend/catalog/aclchk.c 2001/06/14 04:06:32
***************
*** 32,37 ****
--- 32,38 ----
#include "parser/parse_func.h"
#include "utils/acl.h"
#include "utils/syscache.h"
+ #include "utils/temprel.h"
static int32 aclcheck(Acl *acl, AclId id, AclIdType idtype, AclMode mode);
***************
*** 437,443 ****
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
! strncmp(relname, "pg_temp.", strlen("pg_temp.")) != 0 &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG
--- 438,444 ----
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
! !is_temp_relname(relname) &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG
Index: src/backend/catalog/heap.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/heap.c,v
retrieving revision 1.167
diff -c -r1.167 heap.c
*** src/backend/catalog/heap.c 2001/06/12 05:55:49 1.167
--- src/backend/catalog/heap.c 2001/06/14 04:06:38
***************
*** 281,288 ****
* replace relname of caller with a unique name for a temp
* relation
*/
! snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u",
! (int) MyProcPid, uniqueId++);
}
/*
--- 281,288 ----
* replace relname of caller with a unique name for a temp
* relation
*/
! snprintf(relname, NAMEDATALEN, "%s.%d.%u",
! PG_TEMP_REL_PREFIX, (int) MyProcPid, uniqueId++);
}
/*
***************
*** 874,910 ****
}
- /* ----------------------------------------------------------------
- * heap_drop_with_catalog - removes all record of named relation from catalogs
- *
- * 1) open relation, check for existence, etc.
- * 2) remove inheritance information
- * 3) remove indexes
- * 4) remove pg_class tuple
- * 5) remove pg_attribute tuples and related descriptions
- * 6) remove pg_description tuples
- * 7) remove pg_type tuples
- * 8) RemoveConstraints ()
- * 9) unlink relation
- *
- * old comments
- * Except for vital relations, removes relation from
- * relation catalog, and related attributes from
- * attribute catalog (needed?). (Anything else?)
- *
- * get proper relation from relation catalog (if not arg)
- * scan attribute catalog deleting attributes of reldesc
- * (necessary?)
- * delete relation from relation catalog
- * (How are the tuples of the relation discarded?)
- *
- * XXX Must fix to work with indexes.
- * There may be a better order for doing things.
- * Problems with destroying a deleted database--cannot create
- * a struct reldesc without having an open file descriptor.
- * ----------------------------------------------------------------
- */
-
/* --------------------------------
* RelationRemoveInheritance
*
--- 874,879 ----
***************
*** 1334,1343 ****
heap_close(pg_type_desc, RowExclusiveLock);
}
! /* --------------------------------
! * heap_drop_with_catalog
*
! * --------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
--- 1303,1337 ----
heap_close(pg_type_desc, RowExclusiveLock);
}
! /* ----------------------------------------------------------------
! * heap_drop_with_catalog - removes all record of named relation from catalogs
*
! * 1) open relation, check for existence, etc.
! * 2) remove inheritance information
! * 3) remove indexes
! * 4) remove pg_class tuple
! * 5) remove pg_attribute tuples and related descriptions
! * 6) remove pg_description tuples
! * 7) remove pg_type tuples
! * 8) RemoveConstraints ()
! * 9) unlink relation
! *
! * old comments
! * Except for vital relations, removes relation from
! * relation catalog, and related attributes from
! * attribute catalog (needed?). (Anything else?)
! *
! * get proper relation from relation catalog (if not arg)
! * scan attribute catalog deleting attributes of reldesc
! * (necessary?)
! * delete relation from relation catalog
! * (How are the tuples of the relation discarded?)
! *
! * XXX Must fix to work with indexes.
! * There may be a better order for doing things.
! * Problems with destroying a deleted database--cannot create
! * a struct reldesc without having an open file descriptor.
! * ----------------------------------------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
***************
*** 1360,1367 ****
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
! if (!istemp && !allow_system_table_mods &&
! IsSystemRelationName(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));
--- 1354,1363 ----
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
! if (!istemp &&
! !allow_system_table_mods &&
! IsSystemRelationName(RelationGetRelationName(rel)) &&
! !is_temp_relname(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));
Index: src/backend/commands/vacuum.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/commands/vacuum.c,v
retrieving revision 1.196
diff -c -r1.196 vacuum.c
*** src/backend/commands/vacuum.c 2001/06/13 21:44:40 1.196
--- src/backend/commands/vacuum.c 2001/06/14 04:06:40
***************
*** 491,497 ****
vacuum_pages.num_pages = fraged_pages.num_pages = 0;
scan_heap(vacrelstats, onerel, &vacuum_pages, &fraged_pages);
if (IsIgnoringSystemIndexes() &&
! IsSystemRelationName(RelationGetRelationName(onerel)))
reindex = true;
/* Now open indices */
--- 491,498 ----
vacuum_pages.num_pages = fraged_pages.num_pages = 0;
scan_heap(vacrelstats, onerel, &vacuum_pages, &fraged_pages);
if (IsIgnoringSystemIndexes() &&
! IsSystemRelationName(RelationGetRelationName(onerel)) &&
! !is_temp_relname(RelationGetRelationName(onerel)))
reindex = true;
/* Now open indices */
Index: src/backend/tcop/utility.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/tcop/utility.c,v
retrieving revision 1.113
diff -c -r1.113 utility.c
*** src/backend/tcop/utility.c 2001/06/09 23:21:54 1.113
--- src/backend/tcop/utility.c 2001/06/14 04:06:44
***************
*** 46,51 ****
--- 46,52 ----
#include "utils/acl.h"
#include "utils/ps_status.h"
#include "utils/syscache.h"
+ #include "utils/temprel.h"
#include "access/xlog.h"
/*
***************
*** 120,126 ****
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
! if (!allowSystemTableMods && IsSystemRelationName(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);
--- 121,128 ----
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
! if (!allowSystemTableMods && IsSystemRelationName(name) &&
! !is_temp_relname(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);
Index: src/include/utils/temprel.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/utils/temprel.h,v
retrieving revision 1.15
diff -c -r1.15 temprel.h
*** src/include/utils/temprel.h 2001/03/22 04:01:14 1.15
--- src/include/utils/temprel.h 2001/06/14 04:06:47
***************
*** 16,21 ****
--- 16,26 ----
#include "access/htup.h"
+ #define PG_TEMP_REL_PREFIX "pg_temp"
+
+ #define is_temp_relname(relname) \
+ (!strncmp(relname, PG_TEMP_REL_PREFIX, strlen(PG_TEMP_REL_PREFIX)))
+
extern void create_temp_relation(const char *relname,
HeapTuple pg_class_tuple);
extern void remove_temp_rel_by_relid(Oid relid);
Attachments:
[text/plain] /pgpatches/temp (8.1K, ../../[email protected]/2-%2Fpgpatches%2Ftemp)
download | inline:
Index: src/backend/catalog/aclchk.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/aclchk.c,v
retrieving revision 1.50
diff -c -r1.50 aclchk.c
*** src/backend/catalog/aclchk.c 2001/06/09 23:21:54 1.50
--- src/backend/catalog/aclchk.c 2001/06/14 04:06:32
***************
*** 32,37 ****
--- 32,38 ----
#include "parser/parse_func.h"
#include "utils/acl.h"
#include "utils/syscache.h"
+ #include "utils/temprel.h"
static int32 aclcheck(Acl *acl, AclId id, AclIdType idtype, AclMode mode);
***************
*** 437,443 ****
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
! strncmp(relname, "pg_temp.", strlen("pg_temp.")) != 0 &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG
--- 438,444 ----
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
! !is_temp_relname(relname) &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG
Index: src/backend/catalog/heap.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/heap.c,v
retrieving revision 1.167
diff -c -r1.167 heap.c
*** src/backend/catalog/heap.c 2001/06/12 05:55:49 1.167
--- src/backend/catalog/heap.c 2001/06/14 04:06:38
***************
*** 281,288 ****
* replace relname of caller with a unique name for a temp
* relation
*/
! snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u",
! (int) MyProcPid, uniqueId++);
}
/*
--- 281,288 ----
* replace relname of caller with a unique name for a temp
* relation
*/
! snprintf(relname, NAMEDATALEN, "%s.%d.%u",
! PG_TEMP_REL_PREFIX, (int) MyProcPid, uniqueId++);
}
/*
***************
*** 874,910 ****
}
- /* ----------------------------------------------------------------
- * heap_drop_with_catalog - removes all record of named relation from catalogs
- *
- * 1) open relation, check for existence, etc.
- * 2) remove inheritance information
- * 3) remove indexes
- * 4) remove pg_class tuple
- * 5) remove pg_attribute tuples and related descriptions
- * 6) remove pg_description tuples
- * 7) remove pg_type tuples
- * 8) RemoveConstraints ()
- * 9) unlink relation
- *
- * old comments
- * Except for vital relations, removes relation from
- * relation catalog, and related attributes from
- * attribute catalog (needed?). (Anything else?)
- *
- * get proper relation from relation catalog (if not arg)
- * scan attribute catalog deleting attributes of reldesc
- * (necessary?)
- * delete relation from relation catalog
- * (How are the tuples of the relation discarded?)
- *
- * XXX Must fix to work with indexes.
- * There may be a better order for doing things.
- * Problems with destroying a deleted database--cannot create
- * a struct reldesc without having an open file descriptor.
- * ----------------------------------------------------------------
- */
-
/* --------------------------------
* RelationRemoveInheritance
*
--- 874,879 ----
***************
*** 1334,1343 ****
heap_close(pg_type_desc, RowExclusiveLock);
}
! /* --------------------------------
! * heap_drop_with_catalog
*
! * --------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
--- 1303,1337 ----
heap_close(pg_type_desc, RowExclusiveLock);
}
! /* ----------------------------------------------------------------
! * heap_drop_with_catalog - removes all record of named relation from catalogs
*
! * 1) open relation, check for existence, etc.
! * 2) remove inheritance information
! * 3) remove indexes
! * 4) remove pg_class tuple
! * 5) remove pg_attribute tuples and related descriptions
! * 6) remove pg_description tuples
! * 7) remove pg_type tuples
! * 8) RemoveConstraints ()
! * 9) unlink relation
! *
! * old comments
! * Except for vital relations, removes relation from
! * relation catalog, and related attributes from
! * attribute catalog (needed?). (Anything else?)
! *
! * get proper relation from relation catalog (if not arg)
! * scan attribute catalog deleting attributes of reldesc
! * (necessary?)
! * delete relation from relation catalog
! * (How are the tuples of the relation discarded?)
! *
! * XXX Must fix to work with indexes.
! * There may be a better order for doing things.
! * Problems with destroying a deleted database--cannot create
! * a struct reldesc without having an open file descriptor.
! * ----------------------------------------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
***************
*** 1360,1367 ****
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
! if (!istemp && !allow_system_table_mods &&
! IsSystemRelationName(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));
--- 1354,1363 ----
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
! if (!istemp &&
! !allow_system_table_mods &&
! IsSystemRelationName(RelationGetRelationName(rel)) &&
! !is_temp_relname(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));
Index: src/backend/commands/vacuum.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/commands/vacuum.c,v
retrieving revision 1.196
diff -c -r1.196 vacuum.c
*** src/backend/commands/vacuum.c 2001/06/13 21:44:40 1.196
--- src/backend/commands/vacuum.c 2001/06/14 04:06:40
***************
*** 491,497 ****
vacuum_pages.num_pages = fraged_pages.num_pages = 0;
scan_heap(vacrelstats, onerel, &vacuum_pages, &fraged_pages);
if (IsIgnoringSystemIndexes() &&
! IsSystemRelationName(RelationGetRelationName(onerel)))
reindex = true;
/* Now open indices */
--- 491,498 ----
vacuum_pages.num_pages = fraged_pages.num_pages = 0;
scan_heap(vacrelstats, onerel, &vacuum_pages, &fraged_pages);
if (IsIgnoringSystemIndexes() &&
! IsSystemRelationName(RelationGetRelationName(onerel)) &&
! !is_temp_relname(RelationGetRelationName(onerel)))
reindex = true;
/* Now open indices */
Index: src/backend/tcop/utility.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/tcop/utility.c,v
retrieving revision 1.113
diff -c -r1.113 utility.c
*** src/backend/tcop/utility.c 2001/06/09 23:21:54 1.113
--- src/backend/tcop/utility.c 2001/06/14 04:06:44
***************
*** 46,51 ****
--- 46,52 ----
#include "utils/acl.h"
#include "utils/ps_status.h"
#include "utils/syscache.h"
+ #include "utils/temprel.h"
#include "access/xlog.h"
/*
***************
*** 120,126 ****
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
! if (!allowSystemTableMods && IsSystemRelationName(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);
--- 121,128 ----
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
! if (!allowSystemTableMods && IsSystemRelationName(name) &&
! !is_temp_relname(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);
Index: src/include/utils/temprel.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/utils/temprel.h,v
retrieving revision 1.15
diff -c -r1.15 temprel.h
*** src/include/utils/temprel.h 2001/03/22 04:01:14 1.15
--- src/include/utils/temprel.h 2001/06/14 04:06:47
***************
*** 16,21 ****
--- 16,26 ----
#include "access/htup.h"
+ #define PG_TEMP_REL_PREFIX "pg_temp"
+
+ #define is_temp_relname(relname) \
+ (!strncmp(relname, PG_TEMP_REL_PREFIX, strlen(PG_TEMP_REL_PREFIX)))
+
extern void create_temp_relation(const char *relname,
HeapTuple pg_class_tuple);
extern void remove_temp_rel_by_relid(Oid relid);
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Removal of temp tables
@ 2001-06-14 04:52 Tom Lane <[email protected]>
parent: Bruce Momjian <[email protected]>
0 siblings, 3 replies; 333+ messages in thread
From: Tom Lane @ 2001-06-14 04:52 UTC (permalink / raw)
To: Bruce Momjian <[email protected]>; +Cc: PostgreSQL-patches <[email protected]>
Bruce Momjian <[email protected]> writes:
> I am wondering if pg_temp tables should even be seen as system tables by
> IsSystemRelationName(). We have to call them pg_ so user applications
> don't display them, but other than that they aren't like system tables.
> Comments?
This oughta be discussed on pghackers, not just -patches. But my
thought is that we need a three-way distinction; at least some of the
IsSystemRelation checks presumably *should* accept temp relnames, else
we'd not have decided to do it that way in the first place.
Another point is that when we implement schemas (= Real Soon Now, I
trust), the whole business of temprels having different physical and
logical relnames will go away anyhow. Temp rels will become plain rels
that live in a temp schema. So it may not be worth adding further
complexity to support the present approach. We'll just have to rip
it out again ... better to expend the work on making schemas.
regards, tom lane
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: [PATCHES] Removal of temp tables
@ 2001-06-14 05:05 Bruce Momjian <[email protected]>
parent: Tom Lane <[email protected]>
2 siblings, 0 replies; 333+ messages in thread
From: Bruce Momjian @ 2001-06-14 05:05 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: pgsql-hackers
> Bruce Momjian <[email protected]> writes:
> > I am wondering if pg_temp tables should even be seen as system tables by
> > IsSystemRelationName(). We have to call them pg_ so user applications
> > don't display them, but other than that they aren't like system tables.
> > Comments?
>
> This oughta be discussed on pghackers, not just -patches. But my
> thought is that we need a three-way distinction; at least some of the
> IsSystemRelation checks presumably *should* accept temp relnames, else
> we'd not have decided to do it that way in the first place.
>
> Another point is that when we implement schemas (= Real Soon Now, I
> trust), the whole business of temprels having different physical and
> logical relnames will go away anyhow. Temp rels will become plain rels
> that live in a temp schema. So it may not be worth adding further
> complexity to support the present approach. We'll just have to rip
> it out again ... better to expend the work on making schemas.
OK, the patch allows temp tables to be used in the places that need to
drop them. Not sure what else is needed. We don't want people creating
them tables with names like pg_temp because it could conflict with an
existing backend so it seems we will just need to open it up in special
places.
Other comments?
--
Bruce Momjian | http://candle.pha.pa.us
[email protected] | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: [PATCHES] Removal of temp tables
@ 2001-06-14 15:15 Peter Eisentraut <[email protected]>
parent: Tom Lane <[email protected]>
2 siblings, 1 reply; 333+ messages in thread
From: Peter Eisentraut @ 2001-06-14 15:15 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: Bruce Momjian <[email protected]>; pgsql-hackers
Tom Lane writes:
> Another point is that when we implement schemas (= Real Soon Now, I
> trust), the whole business of temprels having different physical and
> logical relnames will go away anyhow. Temp rels will become plain rels
> that live in a temp schema.
I don't think this is the right solution. You should be able to create
temporary tables in any schema you choose (and have permission to). After
all, temporary tables are supposed to act like real tables expect for the
"temporary" aspect.
--
Peter Eisentraut [email protected] http://funkturm.homeip.net/~peter
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: [PATCHES] Removal of temp tables
@ 2001-06-14 15:23 Tom Lane <[email protected]>
parent: Peter Eisentraut <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Tom Lane @ 2001-06-14 15:23 UTC (permalink / raw)
To: Peter Eisentraut <[email protected]>; +Cc: Bruce Momjian <[email protected]>; pgsql-hackers
Peter Eisentraut <[email protected]> writes:
> Tom Lane writes:
>> ... the whole business of temprels having different physical and
>> logical relnames will go away anyhow. Temp rels will become plain rels
>> that live in a temp schema.
> I don't think this is the right solution. You should be able to create
> temporary tables in any schema you choose (and have permission to). After
> all, temporary tables are supposed to act like real tables expect for the
> "temporary" aspect.
If we did that, temp table names would conflict with real table names.
The lack of conflicts is one of the (few ;-)) features of our current
temp table implementation that I really like. Furthermore, I read in
SQL92 sec 4.9
... because global temporary ta-
ble contents are distinct within SQL-sessions, and created local
temporary tables are distinct within <module>s within SQL-sessions,
the effective <schema name> of the schema in which the global tem-
porary table or the created local temporary table is instantiated
is an implementation-dependent <schema name> that may be thought
of as having been effectively derived from the <schema name> of
the schema in which the global temporary table or created local
temporary table is defined and the implementation-dependent SQL-
session identifier associated with the SQL-session. In addition,
the effective <schema name> of the schema in which the created
local temporary table is instantiated may be thought of as being
further qualified by a unique implementation-dependent name associ-
ated with the <module> in which the created local temporary table
is referenced.
This appears to me to require that it be done in the way I suggest:
temp tables live in their own per-backend schema, or schemas.
regards, tom lane
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Removal of temp tables
@ 2001-06-14 16:36 Bruce Momjian <[email protected]>
parent: Tom Lane <[email protected]>
2 siblings, 1 reply; 333+ messages in thread
From: Bruce Momjian @ 2001-06-14 16:36 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: PostgreSQL-patches <[email protected]>
> Bruce Momjian <[email protected]> writes:
> > I am wondering if pg_temp tables should even be seen as system tables by
> > IsSystemRelationName(). We have to call them pg_ so user applications
> > don't display them, but other than that they aren't like system tables.
> > Comments?
>
> This oughta be discussed on pghackers, not just -patches. But my
> thought is that we need a three-way distinction; at least some of the
> IsSystemRelation checks presumably *should* accept temp relnames, else
> we'd not have decided to do it that way in the first place.
>
> Another point is that when we implement schemas (= Real Soon Now, I
> trust), the whole business of temprels having different physical and
> logical relnames will go away anyhow. Temp rels will become plain rels
> that live in a temp schema. So it may not be worth adding further
> complexity to support the present approach. We'll just have to rip
> it out again ... better to expend the work on making schemas.
Here is an updated patch that uses underscores in temp table names so
the DROP doesn't have to quote the table name:
pg_temp_7199_0
I will apply this in two days if there are no other comments.
--
Bruce Momjian | http://candle.pha.pa.us
[email protected] | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
Index: src/backend/catalog/aclchk.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/aclchk.c,v
retrieving revision 1.50
diff -c -r1.50 aclchk.c
*** src/backend/catalog/aclchk.c 2001/06/09 23:21:54 1.50
--- src/backend/catalog/aclchk.c 2001/06/14 16:33:47
***************
*** 32,37 ****
--- 32,38 ----
#include "parser/parse_func.h"
#include "utils/acl.h"
#include "utils/syscache.h"
+ #include "utils/temprel.h"
static int32 aclcheck(Acl *acl, AclId id, AclIdType idtype, AclMode mode);
***************
*** 437,443 ****
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
! strncmp(relname, "pg_temp.", strlen("pg_temp.")) != 0 &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG
--- 438,444 ----
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
! !is_temp_relname(relname) &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG
Index: src/backend/catalog/heap.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/heap.c,v
retrieving revision 1.167
diff -c -r1.167 heap.c
*** src/backend/catalog/heap.c 2001/06/12 05:55:49 1.167
--- src/backend/catalog/heap.c 2001/06/14 16:33:51
***************
*** 281,288 ****
* replace relname of caller with a unique name for a temp
* relation
*/
! snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u",
! (int) MyProcPid, uniqueId++);
}
/*
--- 281,288 ----
* replace relname of caller with a unique name for a temp
* relation
*/
! snprintf(relname, NAMEDATALEN, "%s_%d_%u",
! PG_TEMP_REL_PREFIX, (int) MyProcPid, uniqueId++);
}
/*
***************
*** 874,910 ****
}
- /* ----------------------------------------------------------------
- * heap_drop_with_catalog - removes all record of named relation from catalogs
- *
- * 1) open relation, check for existence, etc.
- * 2) remove inheritance information
- * 3) remove indexes
- * 4) remove pg_class tuple
- * 5) remove pg_attribute tuples and related descriptions
- * 6) remove pg_description tuples
- * 7) remove pg_type tuples
- * 8) RemoveConstraints ()
- * 9) unlink relation
- *
- * old comments
- * Except for vital relations, removes relation from
- * relation catalog, and related attributes from
- * attribute catalog (needed?). (Anything else?)
- *
- * get proper relation from relation catalog (if not arg)
- * scan attribute catalog deleting attributes of reldesc
- * (necessary?)
- * delete relation from relation catalog
- * (How are the tuples of the relation discarded?)
- *
- * XXX Must fix to work with indexes.
- * There may be a better order for doing things.
- * Problems with destroying a deleted database--cannot create
- * a struct reldesc without having an open file descriptor.
- * ----------------------------------------------------------------
- */
-
/* --------------------------------
* RelationRemoveInheritance
*
--- 874,879 ----
***************
*** 1334,1343 ****
heap_close(pg_type_desc, RowExclusiveLock);
}
! /* --------------------------------
! * heap_drop_with_catalog
*
! * --------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
--- 1303,1337 ----
heap_close(pg_type_desc, RowExclusiveLock);
}
! /* ----------------------------------------------------------------
! * heap_drop_with_catalog - removes all record of named relation from catalogs
*
! * 1) open relation, check for existence, etc.
! * 2) remove inheritance information
! * 3) remove indexes
! * 4) remove pg_class tuple
! * 5) remove pg_attribute tuples and related descriptions
! * 6) remove pg_description tuples
! * 7) remove pg_type tuples
! * 8) RemoveConstraints ()
! * 9) unlink relation
! *
! * old comments
! * Except for vital relations, removes relation from
! * relation catalog, and related attributes from
! * attribute catalog (needed?). (Anything else?)
! *
! * get proper relation from relation catalog (if not arg)
! * scan attribute catalog deleting attributes of reldesc
! * (necessary?)
! * delete relation from relation catalog
! * (How are the tuples of the relation discarded?)
! *
! * XXX Must fix to work with indexes.
! * There may be a better order for doing things.
! * Problems with destroying a deleted database--cannot create
! * a struct reldesc without having an open file descriptor.
! * ----------------------------------------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
***************
*** 1360,1367 ****
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
! if (!istemp && !allow_system_table_mods &&
! IsSystemRelationName(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));
--- 1354,1363 ----
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
! if (!istemp &&
! !allow_system_table_mods &&
! IsSystemRelationName(RelationGetRelationName(rel)) &&
! !is_temp_relname(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));
Index: src/backend/commands/vacuum.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/commands/vacuum.c,v
retrieving revision 1.196
diff -c -r1.196 vacuum.c
*** src/backend/commands/vacuum.c 2001/06/13 21:44:40 1.196
--- src/backend/commands/vacuum.c 2001/06/14 16:33:53
***************
*** 491,497 ****
vacuum_pages.num_pages = fraged_pages.num_pages = 0;
scan_heap(vacrelstats, onerel, &vacuum_pages, &fraged_pages);
if (IsIgnoringSystemIndexes() &&
! IsSystemRelationName(RelationGetRelationName(onerel)))
reindex = true;
/* Now open indices */
--- 491,498 ----
vacuum_pages.num_pages = fraged_pages.num_pages = 0;
scan_heap(vacrelstats, onerel, &vacuum_pages, &fraged_pages);
if (IsIgnoringSystemIndexes() &&
! IsSystemRelationName(RelationGetRelationName(onerel)) &&
! !is_temp_relname(RelationGetRelationName(onerel)))
reindex = true;
/* Now open indices */
Index: src/backend/storage/file/fd.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/storage/file/fd.c,v
retrieving revision 1.81
diff -c -r1.81 fd.c
*** src/backend/storage/file/fd.c 2001/06/11 04:12:29 1.81
--- src/backend/storage/file/fd.c 2001/06/14 16:34:02
***************
*** 756,762 ****
* transaction and database instance.
*/
snprintf(tempfilepath, sizeof(tempfilepath),
! "%s/%s%d.%ld", PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
MyProcPid, tempFileCounter++);
/*
--- 756,762 ----
* transaction and database instance.
*/
snprintf(tempfilepath, sizeof(tempfilepath),
! "%s/%s%d_%ld", PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
MyProcPid, tempFileCounter++);
/*
Index: src/backend/tcop/utility.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/tcop/utility.c,v
retrieving revision 1.113
diff -c -r1.113 utility.c
*** src/backend/tcop/utility.c 2001/06/09 23:21:54 1.113
--- src/backend/tcop/utility.c 2001/06/14 16:34:02
***************
*** 46,51 ****
--- 46,52 ----
#include "utils/acl.h"
#include "utils/ps_status.h"
#include "utils/syscache.h"
+ #include "utils/temprel.h"
#include "access/xlog.h"
/*
***************
*** 120,126 ****
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
! if (!allowSystemTableMods && IsSystemRelationName(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);
--- 121,128 ----
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
! if (!allowSystemTableMods && IsSystemRelationName(name) &&
! !is_temp_relname(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);
Index: src/include/utils/temprel.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/utils/temprel.h,v
retrieving revision 1.15
diff -c -r1.15 temprel.h
*** src/include/utils/temprel.h 2001/03/22 04:01:14 1.15
--- src/include/utils/temprel.h 2001/06/14 16:34:03
***************
*** 16,21 ****
--- 16,26 ----
#include "access/htup.h"
+ #define PG_TEMP_REL_PREFIX "pg_temp"
+
+ #define is_temp_relname(relname) \
+ (!strncmp(relname, PG_TEMP_REL_PREFIX, strlen(PG_TEMP_REL_PREFIX)))
+
extern void create_temp_relation(const char *relname,
HeapTuple pg_class_tuple);
extern void remove_temp_rel_by_relid(Oid relid);
Attachments:
[text/plain] /pgpatches/temp (8.9K, ../../[email protected]/2-%2Fpgpatches%2Ftemp)
download | inline:
Index: src/backend/catalog/aclchk.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/aclchk.c,v
retrieving revision 1.50
diff -c -r1.50 aclchk.c
*** src/backend/catalog/aclchk.c 2001/06/09 23:21:54 1.50
--- src/backend/catalog/aclchk.c 2001/06/14 16:33:47
***************
*** 32,37 ****
--- 32,38 ----
#include "parser/parse_func.h"
#include "utils/acl.h"
#include "utils/syscache.h"
+ #include "utils/temprel.h"
static int32 aclcheck(Acl *acl, AclId id, AclIdType idtype, AclMode mode);
***************
*** 437,443 ****
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
! strncmp(relname, "pg_temp.", strlen("pg_temp.")) != 0 &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG
--- 438,444 ----
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
! !is_temp_relname(relname) &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG
Index: src/backend/catalog/heap.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/heap.c,v
retrieving revision 1.167
diff -c -r1.167 heap.c
*** src/backend/catalog/heap.c 2001/06/12 05:55:49 1.167
--- src/backend/catalog/heap.c 2001/06/14 16:33:51
***************
*** 281,288 ****
* replace relname of caller with a unique name for a temp
* relation
*/
! snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u",
! (int) MyProcPid, uniqueId++);
}
/*
--- 281,288 ----
* replace relname of caller with a unique name for a temp
* relation
*/
! snprintf(relname, NAMEDATALEN, "%s_%d_%u",
! PG_TEMP_REL_PREFIX, (int) MyProcPid, uniqueId++);
}
/*
***************
*** 874,910 ****
}
- /* ----------------------------------------------------------------
- * heap_drop_with_catalog - removes all record of named relation from catalogs
- *
- * 1) open relation, check for existence, etc.
- * 2) remove inheritance information
- * 3) remove indexes
- * 4) remove pg_class tuple
- * 5) remove pg_attribute tuples and related descriptions
- * 6) remove pg_description tuples
- * 7) remove pg_type tuples
- * 8) RemoveConstraints ()
- * 9) unlink relation
- *
- * old comments
- * Except for vital relations, removes relation from
- * relation catalog, and related attributes from
- * attribute catalog (needed?). (Anything else?)
- *
- * get proper relation from relation catalog (if not arg)
- * scan attribute catalog deleting attributes of reldesc
- * (necessary?)
- * delete relation from relation catalog
- * (How are the tuples of the relation discarded?)
- *
- * XXX Must fix to work with indexes.
- * There may be a better order for doing things.
- * Problems with destroying a deleted database--cannot create
- * a struct reldesc without having an open file descriptor.
- * ----------------------------------------------------------------
- */
-
/* --------------------------------
* RelationRemoveInheritance
*
--- 874,879 ----
***************
*** 1334,1343 ****
heap_close(pg_type_desc, RowExclusiveLock);
}
! /* --------------------------------
! * heap_drop_with_catalog
*
! * --------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
--- 1303,1337 ----
heap_close(pg_type_desc, RowExclusiveLock);
}
! /* ----------------------------------------------------------------
! * heap_drop_with_catalog - removes all record of named relation from catalogs
*
! * 1) open relation, check for existence, etc.
! * 2) remove inheritance information
! * 3) remove indexes
! * 4) remove pg_class tuple
! * 5) remove pg_attribute tuples and related descriptions
! * 6) remove pg_description tuples
! * 7) remove pg_type tuples
! * 8) RemoveConstraints ()
! * 9) unlink relation
! *
! * old comments
! * Except for vital relations, removes relation from
! * relation catalog, and related attributes from
! * attribute catalog (needed?). (Anything else?)
! *
! * get proper relation from relation catalog (if not arg)
! * scan attribute catalog deleting attributes of reldesc
! * (necessary?)
! * delete relation from relation catalog
! * (How are the tuples of the relation discarded?)
! *
! * XXX Must fix to work with indexes.
! * There may be a better order for doing things.
! * Problems with destroying a deleted database--cannot create
! * a struct reldesc without having an open file descriptor.
! * ----------------------------------------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
***************
*** 1360,1367 ****
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
! if (!istemp && !allow_system_table_mods &&
! IsSystemRelationName(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));
--- 1354,1363 ----
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
! if (!istemp &&
! !allow_system_table_mods &&
! IsSystemRelationName(RelationGetRelationName(rel)) &&
! !is_temp_relname(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));
Index: src/backend/commands/vacuum.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/commands/vacuum.c,v
retrieving revision 1.196
diff -c -r1.196 vacuum.c
*** src/backend/commands/vacuum.c 2001/06/13 21:44:40 1.196
--- src/backend/commands/vacuum.c 2001/06/14 16:33:53
***************
*** 491,497 ****
vacuum_pages.num_pages = fraged_pages.num_pages = 0;
scan_heap(vacrelstats, onerel, &vacuum_pages, &fraged_pages);
if (IsIgnoringSystemIndexes() &&
! IsSystemRelationName(RelationGetRelationName(onerel)))
reindex = true;
/* Now open indices */
--- 491,498 ----
vacuum_pages.num_pages = fraged_pages.num_pages = 0;
scan_heap(vacrelstats, onerel, &vacuum_pages, &fraged_pages);
if (IsIgnoringSystemIndexes() &&
! IsSystemRelationName(RelationGetRelationName(onerel)) &&
! !is_temp_relname(RelationGetRelationName(onerel)))
reindex = true;
/* Now open indices */
Index: src/backend/storage/file/fd.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/storage/file/fd.c,v
retrieving revision 1.81
diff -c -r1.81 fd.c
*** src/backend/storage/file/fd.c 2001/06/11 04:12:29 1.81
--- src/backend/storage/file/fd.c 2001/06/14 16:34:02
***************
*** 756,762 ****
* transaction and database instance.
*/
snprintf(tempfilepath, sizeof(tempfilepath),
! "%s/%s%d.%ld", PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
MyProcPid, tempFileCounter++);
/*
--- 756,762 ----
* transaction and database instance.
*/
snprintf(tempfilepath, sizeof(tempfilepath),
! "%s/%s%d_%ld", PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
MyProcPid, tempFileCounter++);
/*
Index: src/backend/tcop/utility.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/tcop/utility.c,v
retrieving revision 1.113
diff -c -r1.113 utility.c
*** src/backend/tcop/utility.c 2001/06/09 23:21:54 1.113
--- src/backend/tcop/utility.c 2001/06/14 16:34:02
***************
*** 46,51 ****
--- 46,52 ----
#include "utils/acl.h"
#include "utils/ps_status.h"
#include "utils/syscache.h"
+ #include "utils/temprel.h"
#include "access/xlog.h"
/*
***************
*** 120,126 ****
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
! if (!allowSystemTableMods && IsSystemRelationName(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);
--- 121,128 ----
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
! if (!allowSystemTableMods && IsSystemRelationName(name) &&
! !is_temp_relname(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);
Index: src/include/utils/temprel.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/utils/temprel.h,v
retrieving revision 1.15
diff -c -r1.15 temprel.h
*** src/include/utils/temprel.h 2001/03/22 04:01:14 1.15
--- src/include/utils/temprel.h 2001/06/14 16:34:03
***************
*** 16,21 ****
--- 16,26 ----
#include "access/htup.h"
+ #define PG_TEMP_REL_PREFIX "pg_temp"
+
+ #define is_temp_relname(relname) \
+ (!strncmp(relname, PG_TEMP_REL_PREFIX, strlen(PG_TEMP_REL_PREFIX)))
+
extern void create_temp_relation(const char *relname,
HeapTuple pg_class_tuple);
extern void remove_temp_rel_by_relid(Oid relid);
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Removal of temp tables
@ 2001-06-14 17:13 Tom Lane <[email protected]>
parent: Bruce Momjian <[email protected]>
0 siblings, 1 reply; 333+ messages in thread
From: Tom Lane @ 2001-06-14 17:13 UTC (permalink / raw)
To: Bruce Momjian <[email protected]>; +Cc: PostgreSQL-patches <[email protected]>
Bruce Momjian <[email protected]> writes:
> Here is an updated patch that uses underscores in temp table names so
> the DROP doesn't have to quote the table name:
That seems like a reasonable idea, but don't do it to temp file
names, ie, drop this part of the diff:
> *** src/backend/storage/file/fd.c 2001/06/11 04:12:29 1.81
> --- src/backend/storage/file/fd.c 2001/06/14 16:34:02
> ***************
> *** 756,762 ****
> * transaction and database instance.
> */
> snprintf(tempfilepath, sizeof(tempfilepath),
> ! "%s/%s%d.%ld", PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
> MyProcPid, tempFileCounter++);
> /*
> --- 756,762 ----
> * transaction and database instance.
> */
> snprintf(tempfilepath, sizeof(tempfilepath),
> ! "%s/%s%d_%ld", PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
> MyProcPid, tempFileCounter++);
> /*
There's no reason to spell temp file names as if they were rel names,
and probably it's best not to make them look the same.
Also, an item I've ranted about before:
> + #define is_temp_relname(relname) \
> + (!strncmp(relname, PG_TEMP_REL_PREFIX, strlen(PG_TEMP_REL_PREFIX)))
It's bad style to treat the result of strcmp or strncmp as though it
were a boolean, cf
http://fts.postgresql.org/db/mw/msg.html?mid=68294
Write (strncmp(...) == 0) instead.
Otherwise the patch seems reasonable, although I wonder what your
motivation was for choosing these particular IsSystemRelationName calls
to tweak. It looks like you did more than the minimum needed to allow
a DROP TABLE; why these extra ones and not others? (Not that I'm
encouraging you to go around and hit every IsSystemRelationName call.
If you did, that'll just be more changes that I suspect we'll have to
remove again in the long run. I'm just curious why you touched, for
example, VACUUM.)
regards, tom lane
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Removal of temp tables
@ 2001-06-14 17:25 Bruce Momjian <[email protected]>
parent: Tom Lane <[email protected]>
0 siblings, 1 reply; 333+ messages in thread
From: Bruce Momjian @ 2001-06-14 17:25 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: PostgreSQL-patches <[email protected]>
> Bruce Momjian <[email protected]> writes:
> > Here is an updated patch that uses underscores in temp table names so
> > the DROP doesn't have to quote the table name:
>
> That seems like a reasonable idea, but don't do it to temp file
> names, ie, drop this part of the diff:
>
> > *** src/backend/storage/file/fd.c 2001/06/11 04:12:29 1.81
> > --- src/backend/storage/file/fd.c 2001/06/14 16:34:02
> > ***************
> > *** 756,762 ****
> > * transaction and database instance.
> > */
> > snprintf(tempfilepath, sizeof(tempfilepath),
> > ! "%s/%s%d.%ld", PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
> > MyProcPid, tempFileCounter++);
>
> > /*
> > --- 756,762 ----
> > * transaction and database instance.
> > */
> > snprintf(tempfilepath, sizeof(tempfilepath),
> > ! "%s/%s%d_%ld", PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
> > MyProcPid, tempFileCounter++);
>
> > /*
>
> There's no reason to spell temp file names as if they were rel names,
> and probably it's best not to make them look the same.
I was wondering that. The old vacuum file detection patch had the sort
files going into /pg_sorttemp and files called pid_. Your changes made
it pg_tempfile directory and pg_temp file names. I like the older names
that made them clear they were _not_ temp tables. Seemed you wanted
them to have similar names for reasons I couldn't figure.
I don't care if the sort files have dots so I will remove that part of
the patch, but I think we should consider making the sort files more
different than they are now --- dots vs. underscores.
> Also, an item I've ranted about before:
>
> > + #define is_temp_relname(relname) \
> > + (!strncmp(relname, PG_TEMP_REL_PREFIX, strlen(PG_TEMP_REL_PREFIX)))
>
> It's bad style to treat the result of strcmp or strncmp as though it
> were a boolean, cf
> http://fts.postgresql.org/db/mw/msg.html?mid=68294
> Write (strncmp(...) == 0) instead.
OK, changed.
> Otherwise the patch seems reasonable, although I wonder what your
> motivation was for choosing these particular IsSystemRelationName calls
> to tweak. It looks like you did more than the minimum needed to allow
> a DROP TABLE; why these extra ones and not others? (Not that I'm
> encouraging you to go around and hit every IsSystemRelationName call.
> If you did, that'll just be more changes that I suspect we'll have to
> remove again in the long run. I'm just curious why you touched, for
> example, VACUUM.)
I removed the vacuum part. I added it because it looked particularly
bad to do REINDEX on temp tables but I have no reason to know that for
sure.
Patch attached.
--
Bruce Momjian | http://candle.pha.pa.us
[email protected] | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Removal of temp tables
@ 2001-06-14 17:51 Tom Lane <[email protected]>
parent: Bruce Momjian <[email protected]>
0 siblings, 1 reply; 333+ messages in thread
From: Tom Lane @ 2001-06-14 17:51 UTC (permalink / raw)
To: Bruce Momjian <[email protected]>; +Cc: PostgreSQL-patches <[email protected]>
Bruce Momjian <[email protected]> writes:
> I was wondering that. The old vacuum file detection patch had the sort
> files going into /pg_sorttemp and files called pid_. Your changes made
> it pg_tempfile directory and pg_temp file names. I like the older names
> that made them clear they were _not_ temp tables. Seemed you wanted
> them to have similar names for reasons I couldn't figure.
I'm not wedded to those names; if you have a better idea, let's hear it.
I changed it because I didn't like the use of the word "sort"; temp
files are not used only for sorts, but for several other things, and so
I wanted to see them called temp files not sorttemp files. But if you
want to change them so that they look even less like the logical names
of temp relations, that's OK with me.
regards, tom lane
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Removal of temp tables
@ 2001-06-14 17:53 Bruce Momjian <[email protected]>
parent: Tom Lane <[email protected]>
0 siblings, 1 reply; 333+ messages in thread
From: Bruce Momjian @ 2001-06-14 17:53 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: PostgreSQL-patches <[email protected]>
> Bruce Momjian <[email protected]> writes:
> > I was wondering that. The old vacuum file detection patch had the sort
> > files going into /pg_sorttemp and files called pid_. Your changes made
> > it pg_tempfile directory and pg_temp file names. I like the older names
> > that made them clear they were _not_ temp tables. Seemed you wanted
> > them to have similar names for reasons I couldn't figure.
>
> I'm not wedded to those names; if you have a better idea, let's hear it.
> I changed it because I didn't like the use of the word "sort"; temp
> files are not used only for sorts, but for several other things, and so
> I wanted to see them called temp files not sorttemp files. But if you
> want to change them so that they look even less like the logical names
> of temp relations, that's OK with me.
OK, I will do that. What else do we do with them except sorts? Seems
pid_ was a good file name because they are always based on pid in
storage/file/fd.c. The directory could be called simply 'tempfile' with
no pg_. How is that?
--
Bruce Momjian | http://candle.pha.pa.us
[email protected] | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Removal of temp tables
@ 2001-06-14 18:10 Tom Lane <[email protected]>
parent: Bruce Momjian <[email protected]>
0 siblings, 2 replies; 333+ messages in thread
From: Tom Lane @ 2001-06-14 18:10 UTC (permalink / raw)
To: Bruce Momjian <[email protected]>; +Cc: PostgreSQL-patches <[email protected]>
Bruce Momjian <[email protected]> writes:
> What else do we do with them except sorts?
Hash joins. Materialize nodes. Not to mention that sorting is used for
things that aren't obviously sorts (SELECT count(distinct foo), for
example).
> Seems
> pid_ was a good file name because they are always based on pid in
> storage/file/fd.c. The directory could be called simply 'tempfile' with
> no pg_. How is that?
You had that to begin with, and I changed it because I thought it was a
bad idea. The directory name and file name should both make perfectly
clear that the files are temp files belonging to Postgres. For example,
it would be unsafe to make pg_tempfiles be a symlink pointing to a temp
directory shared with other apps if there was any risk of temp file name
collisions. (Not sure you'd do that anyway, because of security issues,
but let's not foreclose it with a poor choice of file names.) A purely
numeric file name for temp files is a particularly bad idea because it
looks too much like our numeric names for table data files. Don't
eliminate a hypothetical confusion factor between relnames and filenames
(which are never seen in the same context anyway) by introducing one
between filenames and other filenames.
If you don't like pg_temp here, maybe post_temp? pgsql_temp?
regards, tom lane
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Removal of temp tables
@ 2001-06-14 18:18 Bruce Momjian <[email protected]>
parent: Tom Lane <[email protected]>
1 sibling, 0 replies; 333+ messages in thread
From: Bruce Momjian @ 2001-06-14 18:18 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: PostgreSQL-patches <[email protected]>
> Bruce Momjian <[email protected]> writes:
> > What else do we do with them except sorts?
>
> Hash joins. Materialize nodes. Not to mention that sorting is used for
> things that aren't obviously sorts (SELECT count(distinct foo), for
> example).
Oh, I didn't know that. OK.
> > Seems
> > pid_ was a good file name because they are always based on pid in
> > storage/file/fd.c. The directory could be called simply 'tempfile' with
> > no pg_. How is that?
>
> You had that to begin with, and I changed it because I thought it was a
> bad idea. The directory name and file name should both make perfectly
> clear that the files are temp files belonging to Postgres. For example,
> it would be unsafe to make pg_tempfiles be a symlink pointing to a temp
> directory shared with other apps if there was any risk of temp file name
> collisions. (Not sure you'd do that anyway, because of security issues,
> but let's not foreclose it with a poor choice of file names.) A purely
> numeric file name for temp files is a particularly bad idea because it
> looks too much like our numeric names for table data files. Don't
> eliminate a hypothetical confusion factor between relnames and filenames
> (which are never seen in the same context anyway) by introducing one
> between filenames and other filenames.
OK, I see, you think it could share a directory with another app. Now I
see why you used pg_temp.
>
> If you don't like pg_temp here, maybe post_temp? pgsql_temp?
OK, pgsql_temp works for me. Everytime I see pg_ I think system table.
I will use pgsql_temp for directory and file names.
--
Bruce Momjian | http://candle.pha.pa.us
[email protected] | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Removal of temp tables
@ 2001-06-14 19:46 Bruce Momjian <[email protected]>
parent: Tom Lane <[email protected]>
1 sibling, 1 reply; 333+ messages in thread
From: Bruce Momjian @ 2001-06-14 19:46 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: PostgreSQL-patches <[email protected]>
> You had that to begin with, and I changed it because I thought it was a
> bad idea. The directory name and file name should both make perfectly
> clear that the files are temp files belonging to Postgres. For example,
> it would be unsafe to make pg_tempfiles be a symlink pointing to a temp
> directory shared with other apps if there was any risk of temp file name
> collisions. (Not sure you'd do that anyway, because of security issues,
> but let's not foreclose it with a poor choice of file names.) A purely
> numeric file name for temp files is a particularly bad idea because it
> looks too much like our numeric names for table data files. Don't
> eliminate a hypothetical confusion factor between relnames and filenames
> (which are never seen in the same context anyway) by introducing one
> between filenames and other filenames.
>
> If you don't like pg_temp here, maybe post_temp? pgsql_temp?
What if I call the directory tmp or pgsql_tmp and the files
pgsql_pid_#.#?
--
Bruce Momjian | http://candle.pha.pa.us
[email protected] | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Removal of temp tables
@ 2001-06-14 20:15 Tom Lane <[email protected]>
parent: Bruce Momjian <[email protected]>
0 siblings, 2 replies; 333+ messages in thread
From: Tom Lane @ 2001-06-14 20:15 UTC (permalink / raw)
To: Bruce Momjian <[email protected]>; +Cc: PostgreSQL-patches <[email protected]>
Bruce Momjian <[email protected]> writes:
>> If you don't like pg_temp here, maybe post_temp? pgsql_temp?
> What if I call the directory tmp or pgsql_tmp and the files
> pgsql_pid_#.#?
Why are you so eager not to call temp files "temp"? If you want to
spell it "pgsql_tmp" or "pg_temporary" or something different from
"pg_temp", that's fine, but I really think the files ought to clearly
label themselves as temporary. "pid" is not a clear label. With a
name like that, people might even think they are lock files.
regards, tom lane
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Removal of temp tables
@ 2001-06-14 20:17 Bruce Momjian <[email protected]>
parent: Tom Lane <[email protected]>
1 sibling, 0 replies; 333+ messages in thread
From: Bruce Momjian @ 2001-06-14 20:17 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: PostgreSQL-patches <[email protected]>
> Bruce Momjian <[email protected]> writes:
> >> If you don't like pg_temp here, maybe post_temp? pgsql_temp?
>
> > What if I call the directory tmp or pgsql_tmp and the files
> > pgsql_pid_#.#?
>
> Why are you so eager not to call temp files "temp"? If you want to
> spell it "pgsql_tmp" or "pg_temporary" or something different from
> "pg_temp", that's fine, but I really think the files ought to clearly
> label themselves as temporary. "pid" is not a clear label. With a
> name like that, people might even think they are lock files.
I wanted to call them pid so people knew what the file number meant.
--
Bruce Momjian | http://candle.pha.pa.us
[email protected] | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Removal of temp tables
@ 2001-06-15 00:06 Bruce Momjian <[email protected]>
parent: Tom Lane <[email protected]>
1 sibling, 0 replies; 333+ messages in thread
From: Bruce Momjian @ 2001-06-15 00:06 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: PostgreSQL-patches <[email protected]>
> Bruce Momjian <[email protected]> writes:
> >> If you don't like pg_temp here, maybe post_temp? pgsql_temp?
>
> > What if I call the directory tmp or pgsql_tmp and the files
> > pgsql_pid_#.#?
>
> Why are you so eager not to call temp files "temp"? If you want to
> spell it "pgsql_tmp" or "pg_temporary" or something different from
> "pg_temp", that's fine, but I really think the files ought to clearly
> label themselves as temporary. "pid" is not a clear label. With a
> name like that, people might even think they are lock files.
OK, here is the new version with directories and files called pgsql_tmp.
That doesn't look like it holds temp tables.
--
Bruce Momjian | http://candle.pha.pa.us
[email protected] | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
Index: src/backend/catalog/aclchk.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/aclchk.c,v
retrieving revision 1.50
diff -c -r1.50 aclchk.c
*** src/backend/catalog/aclchk.c 2001/06/09 23:21:54 1.50
--- src/backend/catalog/aclchk.c 2001/06/15 00:01:48
***************
*** 32,37 ****
--- 32,38 ----
#include "parser/parse_func.h"
#include "utils/acl.h"
#include "utils/syscache.h"
+ #include "utils/temprel.h"
static int32 aclcheck(Acl *acl, AclId id, AclIdType idtype, AclMode mode);
***************
*** 437,443 ****
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
! strncmp(relname, "pg_temp.", strlen("pg_temp.")) != 0 &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG
--- 438,444 ----
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
! !is_temp_relname(relname) &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG
Index: src/backend/catalog/heap.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/heap.c,v
retrieving revision 1.167
diff -c -r1.167 heap.c
*** src/backend/catalog/heap.c 2001/06/12 05:55:49 1.167
--- src/backend/catalog/heap.c 2001/06/15 00:01:49
***************
*** 281,288 ****
* replace relname of caller with a unique name for a temp
* relation
*/
! snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u",
! (int) MyProcPid, uniqueId++);
}
/*
--- 281,288 ----
* replace relname of caller with a unique name for a temp
* relation
*/
! snprintf(relname, NAMEDATALEN, "%s_%d_%u",
! PG_TEMP_REL_PREFIX, (int) MyProcPid, uniqueId++);
}
/*
***************
*** 874,910 ****
}
- /* ----------------------------------------------------------------
- * heap_drop_with_catalog - removes all record of named relation from catalogs
- *
- * 1) open relation, check for existence, etc.
- * 2) remove inheritance information
- * 3) remove indexes
- * 4) remove pg_class tuple
- * 5) remove pg_attribute tuples and related descriptions
- * 6) remove pg_description tuples
- * 7) remove pg_type tuples
- * 8) RemoveConstraints ()
- * 9) unlink relation
- *
- * old comments
- * Except for vital relations, removes relation from
- * relation catalog, and related attributes from
- * attribute catalog (needed?). (Anything else?)
- *
- * get proper relation from relation catalog (if not arg)
- * scan attribute catalog deleting attributes of reldesc
- * (necessary?)
- * delete relation from relation catalog
- * (How are the tuples of the relation discarded?)
- *
- * XXX Must fix to work with indexes.
- * There may be a better order for doing things.
- * Problems with destroying a deleted database--cannot create
- * a struct reldesc without having an open file descriptor.
- * ----------------------------------------------------------------
- */
-
/* --------------------------------
* RelationRemoveInheritance
*
--- 874,879 ----
***************
*** 1334,1343 ****
heap_close(pg_type_desc, RowExclusiveLock);
}
! /* --------------------------------
! * heap_drop_with_catalog
*
! * --------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
--- 1303,1337 ----
heap_close(pg_type_desc, RowExclusiveLock);
}
! /* ----------------------------------------------------------------
! * heap_drop_with_catalog - removes all record of named relation from catalogs
*
! * 1) open relation, check for existence, etc.
! * 2) remove inheritance information
! * 3) remove indexes
! * 4) remove pg_class tuple
! * 5) remove pg_attribute tuples and related descriptions
! * 6) remove pg_description tuples
! * 7) remove pg_type tuples
! * 8) RemoveConstraints ()
! * 9) unlink relation
! *
! * old comments
! * Except for vital relations, removes relation from
! * relation catalog, and related attributes from
! * attribute catalog (needed?). (Anything else?)
! *
! * get proper relation from relation catalog (if not arg)
! * scan attribute catalog deleting attributes of reldesc
! * (necessary?)
! * delete relation from relation catalog
! * (How are the tuples of the relation discarded?)
! *
! * XXX Must fix to work with indexes.
! * There may be a better order for doing things.
! * Problems with destroying a deleted database--cannot create
! * a struct reldesc without having an open file descriptor.
! * ----------------------------------------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
***************
*** 1360,1367 ****
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
! if (!istemp && !allow_system_table_mods &&
! IsSystemRelationName(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));
--- 1354,1363 ----
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
! if (!istemp &&
! !allow_system_table_mods &&
! IsSystemRelationName(RelationGetRelationName(rel)) &&
! !is_temp_relname(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));
Index: src/backend/storage/file/fd.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/storage/file/fd.c,v
retrieving revision 1.81
diff -c -r1.81 fd.c
*** src/backend/storage/file/fd.c 2001/06/11 04:12:29 1.81
--- src/backend/storage/file/fd.c 2001/06/15 00:01:52
***************
*** 54,61 ****
/* Filename components for OpenTemporaryFile */
! #define PG_TEMP_FILES_DIR "pg_tempfiles"
! #define PG_TEMP_FILE_PREFIX "pg_temp"
/*
--- 54,61 ----
/* Filename components for OpenTemporaryFile */
! #define PG_TEMP_FILES_DIR "pgsql_tmp"
! #define PG_TEMP_FILE_PREFIX "pgsql_tmp"
/*
Index: src/backend/tcop/utility.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/tcop/utility.c,v
retrieving revision 1.113
diff -c -r1.113 utility.c
*** src/backend/tcop/utility.c 2001/06/09 23:21:54 1.113
--- src/backend/tcop/utility.c 2001/06/15 00:01:52
***************
*** 46,51 ****
--- 46,52 ----
#include "utils/acl.h"
#include "utils/ps_status.h"
#include "utils/syscache.h"
+ #include "utils/temprel.h"
#include "access/xlog.h"
/*
***************
*** 120,126 ****
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
! if (!allowSystemTableMods && IsSystemRelationName(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);
--- 121,128 ----
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
! if (!allowSystemTableMods && IsSystemRelationName(name) &&
! !is_temp_relname(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);
Index: src/include/utils/temprel.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/utils/temprel.h,v
retrieving revision 1.15
diff -c -r1.15 temprel.h
*** src/include/utils/temprel.h 2001/03/22 04:01:14 1.15
--- src/include/utils/temprel.h 2001/06/15 00:01:53
***************
*** 16,21 ****
--- 16,26 ----
#include "access/htup.h"
+ #define PG_TEMP_REL_PREFIX "pg_temp"
+
+ #define is_temp_relname(relname) \
+ (strncmp(relname, PG_TEMP_REL_PREFIX, strlen(PG_TEMP_REL_PREFIX)) == 0)
+
extern void create_temp_relation(const char *relname,
HeapTuple pg_class_tuple);
extern void remove_temp_rel_by_relid(Oid relid);
Attachments:
[text/plain] /pgpatches/temp (7.8K, ../../[email protected]/2-%2Fpgpatches%2Ftemp)
download | inline:
Index: src/backend/catalog/aclchk.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/aclchk.c,v
retrieving revision 1.50
diff -c -r1.50 aclchk.c
*** src/backend/catalog/aclchk.c 2001/06/09 23:21:54 1.50
--- src/backend/catalog/aclchk.c 2001/06/15 00:01:48
***************
*** 32,37 ****
--- 32,38 ----
#include "parser/parse_func.h"
#include "utils/acl.h"
#include "utils/syscache.h"
+ #include "utils/temprel.h"
static int32 aclcheck(Acl *acl, AclId id, AclIdType idtype, AclMode mode);
***************
*** 437,443 ****
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
! strncmp(relname, "pg_temp.", strlen("pg_temp.")) != 0 &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG
--- 438,444 ----
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
! !is_temp_relname(relname) &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG
Index: src/backend/catalog/heap.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/heap.c,v
retrieving revision 1.167
diff -c -r1.167 heap.c
*** src/backend/catalog/heap.c 2001/06/12 05:55:49 1.167
--- src/backend/catalog/heap.c 2001/06/15 00:01:49
***************
*** 281,288 ****
* replace relname of caller with a unique name for a temp
* relation
*/
! snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u",
! (int) MyProcPid, uniqueId++);
}
/*
--- 281,288 ----
* replace relname of caller with a unique name for a temp
* relation
*/
! snprintf(relname, NAMEDATALEN, "%s_%d_%u",
! PG_TEMP_REL_PREFIX, (int) MyProcPid, uniqueId++);
}
/*
***************
*** 874,910 ****
}
- /* ----------------------------------------------------------------
- * heap_drop_with_catalog - removes all record of named relation from catalogs
- *
- * 1) open relation, check for existence, etc.
- * 2) remove inheritance information
- * 3) remove indexes
- * 4) remove pg_class tuple
- * 5) remove pg_attribute tuples and related descriptions
- * 6) remove pg_description tuples
- * 7) remove pg_type tuples
- * 8) RemoveConstraints ()
- * 9) unlink relation
- *
- * old comments
- * Except for vital relations, removes relation from
- * relation catalog, and related attributes from
- * attribute catalog (needed?). (Anything else?)
- *
- * get proper relation from relation catalog (if not arg)
- * scan attribute catalog deleting attributes of reldesc
- * (necessary?)
- * delete relation from relation catalog
- * (How are the tuples of the relation discarded?)
- *
- * XXX Must fix to work with indexes.
- * There may be a better order for doing things.
- * Problems with destroying a deleted database--cannot create
- * a struct reldesc without having an open file descriptor.
- * ----------------------------------------------------------------
- */
-
/* --------------------------------
* RelationRemoveInheritance
*
--- 874,879 ----
***************
*** 1334,1343 ****
heap_close(pg_type_desc, RowExclusiveLock);
}
! /* --------------------------------
! * heap_drop_with_catalog
*
! * --------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
--- 1303,1337 ----
heap_close(pg_type_desc, RowExclusiveLock);
}
! /* ----------------------------------------------------------------
! * heap_drop_with_catalog - removes all record of named relation from catalogs
*
! * 1) open relation, check for existence, etc.
! * 2) remove inheritance information
! * 3) remove indexes
! * 4) remove pg_class tuple
! * 5) remove pg_attribute tuples and related descriptions
! * 6) remove pg_description tuples
! * 7) remove pg_type tuples
! * 8) RemoveConstraints ()
! * 9) unlink relation
! *
! * old comments
! * Except for vital relations, removes relation from
! * relation catalog, and related attributes from
! * attribute catalog (needed?). (Anything else?)
! *
! * get proper relation from relation catalog (if not arg)
! * scan attribute catalog deleting attributes of reldesc
! * (necessary?)
! * delete relation from relation catalog
! * (How are the tuples of the relation discarded?)
! *
! * XXX Must fix to work with indexes.
! * There may be a better order for doing things.
! * Problems with destroying a deleted database--cannot create
! * a struct reldesc without having an open file descriptor.
! * ----------------------------------------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
***************
*** 1360,1367 ****
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
! if (!istemp && !allow_system_table_mods &&
! IsSystemRelationName(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));
--- 1354,1363 ----
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
! if (!istemp &&
! !allow_system_table_mods &&
! IsSystemRelationName(RelationGetRelationName(rel)) &&
! !is_temp_relname(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));
Index: src/backend/storage/file/fd.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/storage/file/fd.c,v
retrieving revision 1.81
diff -c -r1.81 fd.c
*** src/backend/storage/file/fd.c 2001/06/11 04:12:29 1.81
--- src/backend/storage/file/fd.c 2001/06/15 00:01:52
***************
*** 54,61 ****
/* Filename components for OpenTemporaryFile */
! #define PG_TEMP_FILES_DIR "pg_tempfiles"
! #define PG_TEMP_FILE_PREFIX "pg_temp"
/*
--- 54,61 ----
/* Filename components for OpenTemporaryFile */
! #define PG_TEMP_FILES_DIR "pgsql_tmp"
! #define PG_TEMP_FILE_PREFIX "pgsql_tmp"
/*
Index: src/backend/tcop/utility.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/tcop/utility.c,v
retrieving revision 1.113
diff -c -r1.113 utility.c
*** src/backend/tcop/utility.c 2001/06/09 23:21:54 1.113
--- src/backend/tcop/utility.c 2001/06/15 00:01:52
***************
*** 46,51 ****
--- 46,52 ----
#include "utils/acl.h"
#include "utils/ps_status.h"
#include "utils/syscache.h"
+ #include "utils/temprel.h"
#include "access/xlog.h"
/*
***************
*** 120,126 ****
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
! if (!allowSystemTableMods && IsSystemRelationName(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);
--- 121,128 ----
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
! if (!allowSystemTableMods && IsSystemRelationName(name) &&
! !is_temp_relname(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);
Index: src/include/utils/temprel.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/utils/temprel.h,v
retrieving revision 1.15
diff -c -r1.15 temprel.h
*** src/include/utils/temprel.h 2001/03/22 04:01:14 1.15
--- src/include/utils/temprel.h 2001/06/15 00:01:53
***************
*** 16,21 ****
--- 16,26 ----
#include "access/htup.h"
+ #define PG_TEMP_REL_PREFIX "pg_temp"
+
+ #define is_temp_relname(relname) \
+ (strncmp(relname, PG_TEMP_REL_PREFIX, strlen(PG_TEMP_REL_PREFIX)) == 0)
+
extern void create_temp_relation(const char *relname,
HeapTuple pg_class_tuple);
extern void remove_temp_rel_by_relid(Oid relid);
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 333+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 333+ messages in thread
end of thread, other threads:[~2025-08-04 22:05 UTC | newest]
Thread overview: 333+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-14 04:17 Removal of temp tables Bruce Momjian <[email protected]>
2001-06-14 04:52 ` Tom Lane <[email protected]>
2001-06-14 05:05 ` Bruce Momjian <[email protected]>
2001-06-14 15:15 ` Peter Eisentraut <[email protected]>
2001-06-14 15:23 ` Tom Lane <[email protected]>
2001-06-14 16:36 ` Bruce Momjian <[email protected]>
2001-06-14 17:13 ` Tom Lane <[email protected]>
2001-06-14 17:25 ` Bruce Momjian <[email protected]>
2001-06-14 17:51 ` Tom Lane <[email protected]>
2001-06-14 17:53 ` Bruce Momjian <[email protected]>
2001-06-14 18:10 ` Tom Lane <[email protected]>
2001-06-14 18:18 ` Bruce Momjian <[email protected]>
2001-06-14 19:46 ` Bruce Momjian <[email protected]>
2001-06-14 20:15 ` Tom Lane <[email protected]>
2001-06-14 20:17 ` Bruce Momjian <[email protected]>
2001-06-15 00:06 ` Bruce Momjian <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox