agora inbox for [email protected]
help / color / mirror / Atom feedDisable WAL logging to speed up data loading
392+ messages / 14 participants
[nested] [flat]
* Disable WAL logging to speed up data loading
@ 2020-09-29 08:28 [email protected] <[email protected]>
2020-09-29 09:40 ` Re: Disable WAL logging to speed up data loading Amul Sul <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
0 siblings, 2 replies; 392+ messages in thread
From: [email protected] @ 2020-09-29 08:28 UTC (permalink / raw)
To: PostgreSQL Hackers <[email protected]>
Hello,
We'd like to propose a feature to disable WAL to speed up data loading. This was inspired by a feature added in the latest MySQL. I wish you won't fear this feature...
BACKGROUND
========================================
This branches off from [1] as mentioned therein. Briefly speaking, a customer wants to shorten the time for nightly loading of data into their data warehouse as much as possible to be prepared for using the data warehouse for new things.
Currently, they are using Oracle's SQL*Loader with its no-logging feature. They want a similar feature to migrate to Postgres. Other than the data loading performance, they don't want to be concerned about the storage for large volumes of WAL.
In [1], we thought about something like Oracle's per-table no-logging feature, but it seems difficult (or at least not easy.) Meanwhile, I found another feature added in the latest MySQL 8.0.21 [2]. This proposal follows it almost directly. That satisfies the customer request.
As an aside, it's also conceivable that in the near future, users could see the WAL bottleneck (WAL buffer or disk) when they utilize the parallel COPY that is being developed in the community.
FUNCTIONAL SPECIFICATION
========================================
Add a new value 'none' to the server configuration parameter wal_level. With this setting:
* No WAL is emitted.
* The server refuses to start (pg_ctl start fails) after an abnormal shutdown due to power outage, pg_ctl's immediate shutdown, etc, showing a straightforward message like MySQL.
* Features like continuous archiving, pg_basebackup, and streaming/logical replication that requires wal_level >= replica are not available.
* The user can use all features again if you shut down the server successfully after data loading and reset wal_level to a value other than none. He needs to take a base backup or rebuild the replication standby after restarting the server.
In addition to the cosmetic modifications to the manual articles that refer to wal_level, add a clause or paragraphs to the following sections to let users know the availability of this feature.
14.4. Populating a Database
18.6.1. Upgrading Data via pg_dumpall
PROGRAM DESIGN (main point only)
========================================
As in the bootstrap mode (during initdb), when wal_level = none, XLogInsert() does nothing and just returns a fixed value, which is the tail of the last shutdown checkpoint WAL record. As a result, the value is set to the relation page header's LSN field.
In addition, it might be worth having XLogBeginInsert() and XLogRec...() to check wal_level and just return. I don't expect much from this, but it may be interesting to give it a try to see the squeezed performance.
StartupXLOG() checks the wal_level setting in pg_control and quits the startup with ereport(FATAL) accordingly.
[1]
Implement UNLOGGED clause for COPY FROM
https://www.postgresql.org/message-id/[email protected]....
[2]
Disabling Redo Logging
https://dev.mysql.com/doc/refman/8.0/en/innodb-redo-log.html#innodb-disable-redo-logging
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-09-29 09:40 ` Amul Sul <[email protected]>
2020-09-30 02:33 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: Amul Sul @ 2020-09-29 09:40 UTC (permalink / raw)
To: [email protected] <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Tue, Sep 29, 2020 at 1:58 PM [email protected]
<[email protected]> wrote:
>
> Hello,
>
>
> We'd like to propose a feature to disable WAL to speed up data loading. This was inspired by a feature added in the latest MySQL. I wish you won't fear this feature...
>
TWIMW, pg_bulkload contrib module[1], also does the same for the
faster data loading.
Regards,
Amul
1] http://ossc-db.github.io/pg_bulkload/pg_bulkload.html
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 09:40 ` Re: Disable WAL logging to speed up data loading Amul Sul <[email protected]>
@ 2020-09-30 02:33 ` [email protected] <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: [email protected] @ 2020-09-30 02:33 UTC (permalink / raw)
To: 'Amul Sul' <[email protected]>; [email protected] <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
Hi, Amul
> > We'd like to propose a feature to disable WAL to speed up data loading. This
> was inspired by a feature added in the latest MySQL. I wish you won't fear
> this feature...
> >
>
> TWIMW, pg_bulkload contrib module[1], also does the same for the faster data
> loading.
Both features are helpful to make the data loading faster,
but those are different.
There are at least two major merits as their differences to use wal_level='none'.
The first one happens when user upgrades major version by pg_dumpall.
Imagine a case that one user gets a logical backup of whole cluster by pg_dumpall.
The output file contains many COPY commands in it to recreate and upgrade the cluster.
Setting wal_level='none' can be easily used to boost the speed to remake the
cluster of a newer version by setting the wal_level.
OTOH, pg_bulkload can't treat this flow of upgrade in an easy way.
It requires to plan and write the detail of control files or commands for each table manually.
This wouldn't be easy for users.
Secondly,
to use pg_bulkload requires us to use a wrapper command of pg_ctl
like "pg_bulkload -r", which is prepared only for the feature.
This command is used when pg_bulkload is crashed.
The document recommends not to use pg_ctl directly in such a case.
Like this, paying attention to such usages or minor differences of usage is troublesome
while running a long operation of service, without support of the OSS community.
What did you think ?
Regards,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-09-29 12:40 ` Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: Ashutosh Bapat @ 2020-09-29 12:40 UTC (permalink / raw)
To: [email protected] <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
Can they use a database with all unlogged tables?
On Tue, Sep 29, 2020 at 1:58 PM [email protected]
<[email protected]> wrote:
>
> Hello,
>
>
> We'd like to propose a feature to disable WAL to speed up data loading. This was inspired by a feature added in the latest MySQL. I wish you won't fear this feature...
>
>
> BACKGROUND
> ========================================
>
> This branches off from [1] as mentioned therein. Briefly speaking, a customer wants to shorten the time for nightly loading of data into their data warehouse as much as possible to be prepared for using the data warehouse for new things.
>
> Currently, they are using Oracle's SQL*Loader with its no-logging feature. They want a similar feature to migrate to Postgres. Other than the data loading performance, they don't want to be concerned about the storage for large volumes of WAL.
>
> In [1], we thought about something like Oracle's per-table no-logging feature, but it seems difficult (or at least not easy.) Meanwhile, I found another feature added in the latest MySQL 8.0.21 [2]. This proposal follows it almost directly. That satisfies the customer request.
>
> As an aside, it's also conceivable that in the near future, users could see the WAL bottleneck (WAL buffer or disk) when they utilize the parallel COPY that is being developed in the community.
>
>
> FUNCTIONAL SPECIFICATION
> ========================================
>
> Add a new value 'none' to the server configuration parameter wal_level. With this setting:
>
> * No WAL is emitted.
>
> * The server refuses to start (pg_ctl start fails) after an abnormal shutdown due to power outage, pg_ctl's immediate shutdown, etc, showing a straightforward message like MySQL.
>
> * Features like continuous archiving, pg_basebackup, and streaming/logical replication that requires wal_level >= replica are not available.
>
> * The user can use all features again if you shut down the server successfully after data loading and reset wal_level to a value other than none. He needs to take a base backup or rebuild the replication standby after restarting the server.
>
>
> In addition to the cosmetic modifications to the manual articles that refer to wal_level, add a clause or paragraphs to the following sections to let users know the availability of this feature.
>
> 14.4. Populating a Database
> 18.6.1. Upgrading Data via pg_dumpall
>
>
> PROGRAM DESIGN (main point only)
> ========================================
>
> As in the bootstrap mode (during initdb), when wal_level = none, XLogInsert() does nothing and just returns a fixed value, which is the tail of the last shutdown checkpoint WAL record. As a result, the value is set to the relation page header's LSN field.
>
> In addition, it might be worth having XLogBeginInsert() and XLogRec...() to check wal_level and just return. I don't expect much from this, but it may be interesting to give it a try to see the squeezed performance.
>
> StartupXLOG() checks the wal_level setting in pg_control and quits the startup with ereport(FATAL) accordingly.
>
>
> [1]
> Implement UNLOGGED clause for COPY FROM
> https://www.postgresql.org/message-id/[email protected]....
>
> [2]
> Disabling Redo Logging
> https://dev.mysql.com/doc/refman/8.0/en/innodb-redo-log.html#innodb-disable-redo-logging
>
>
> Regards
> Takayuki Tsunakawa
>
>
>
--
Best Wishes,
Ashutosh Bapat
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
@ 2020-09-30 03:10 ` [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-09-30 03:10 UTC (permalink / raw)
To: 'Ashutosh Bapat' <[email protected]>; [email protected] <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
Hello, Ashutosh
> Can they use a database with all unlogged tables?
Unfortunately, no. They want to switch a cluster condition to "without WAL logging"
only when they execute night bulk loading for their data warehouse.
In other words, they would like to keep their other usual operations with WAL.
In addition, using all tables as unlogged brings about
the risk to lose data warehouse's data caused by an unexpected server crash or power outage.
Regards,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-10-01 01:01 ` Fujii Masao <[email protected]>
2020-10-01 02:51 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
0 siblings, 2 replies; 392+ messages in thread
From: Fujii Masao @ 2020-10-01 01:01 UTC (permalink / raw)
To: [email protected] <[email protected]>; 'Ashutosh Bapat' <[email protected]>; [email protected] <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On 2020/09/30 12:10, [email protected] wrote:
> Hello, Ashutosh
>
>> Can they use a database with all unlogged tables?
> Unfortunately, no. They want to switch a cluster condition to "without WAL logging"
> only when they execute night bulk loading for their data warehouse.
> In other words, they would like to keep their other usual operations with WAL.
> In addition, using all tables as unlogged brings about
> the risk to lose data warehouse's data caused by an unexpected server crash or power outage.
But the same issue can happen even in the proposed approach
because Tsunakawa-san explains as follows?
> The server refuses to start (pg_ctl start fails) after an abnormal shutdown due to power outage, pg_ctl's immediate shutdown, etc, showing a straightforward message like MySQL.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
@ 2020-10-01 02:51 ` Kyotaro Horiguchi <[email protected]>
1 sibling, 0 replies; 392+ messages in thread
From: Kyotaro Horiguchi @ 2020-10-01 02:51 UTC (permalink / raw)
To: [email protected]; +Cc: [email protected]; [email protected]; [email protected]; [email protected]
At Thu, 1 Oct 2020 10:01:56 +0900, Fujii Masao <[email protected]> wrote in
>
>
> On 2020/09/30 12:10, [email protected] wrote:
> > Hello, Ashutosh
> >
> >> Can they use a database with all unlogged tables?
> > Unfortunately, no. They want to switch a cluster condition to "without
> > WAL logging"
> > only when they execute night bulk loading for their data warehouse.
> > In other words, they would like to keep their other usual operations
> > with WAL.
> > In addition, using all tables as unlogged brings about
> > the risk to lose data warehouse's data caused by an unexpected server
> > crash or power outage.
>
> But the same issue can happen even in the proposed approach
> because Tsunakawa-san explains as follows?
>
> > The server refuses to start (pg_ctl start fails) after an abnormal
> > shutdown due to power outage, pg_ctl's immediate shutdown, etc,
> > showing a straightforward message like MySQL.
Exactly. Crash safety cannot be a rationale for this feature.
The proposed feature seems to give an advantage to a massive loading
onto a already very large table. Currently turning a large logged
table into an unlogged one runs a table copy that takes a long
time. After the bulk-loading, to put back the table huge amount of WAL
is emitted and a table-copy takes a long time. If we had the
wal_level=none feature, the preparation time is not needed and the
put-back time can be offloaded to online backing-up. The crash-unsafe
period is inevitable but would be shorten by using storage snapshots.
On the other hand, a massive loading to an empty table is efficiently
performed by wal_level=minimal.
As I mentioned in another thread, if ALTER TABLE LOGGED/UNLOGGED
doesn't need a table copy (consequently no insertion WAL are emitted),
it would work. I'm not which is better, or easier to realize.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
@ 2020-10-01 03:04 ` [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-10-01 03:04 UTC (permalink / raw)
To: 'Fujii Masao' <[email protected]>; 'Ashutosh Bapat' <[email protected]>; [email protected] <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
Hello.
> >> Can they use a database with all unlogged tables?
> > Unfortunately, no. They want to switch a cluster condition to "without WAL
> logging"
> > only when they execute night bulk loading for their data warehouse.
> > In other words, they would like to keep their other usual operations with WAL.
> > In addition, using all tables as unlogged brings about the risk to
> > lose data warehouse's data caused by an unexpected server crash or power
> outage.
>
> But the same issue can happen even in the proposed approach because
> Tsunakawa-san explains as follows?
Sorry, my last expression about "to lose data" was not precise.
When unlogged tables are used and the server is crashed unexpectedly,
all data after the last backup is truncated without WAL, right ?
In this case, sequential commands for unlogged tables disappear.
On the other hand, wal_level='none' can be changed to 'minimal' for example.
Therefore, such other sequential operations after the last backup
could be stored in WAL file, when a user applies such a change of wal_level.
I meant this is helpful but didn't this make sense ?
> > The server refuses to start (pg_ctl start fails) after an abnormal shutdown due
> to power outage, pg_ctl's immediate shutdown, etc, showing a straightforward
> message like MySQL.
This is the behavior during wal_level='none'.
> * The user can use all features again if you shut down the server successfully
> after data loading and reset wal_level to a value other than none. He needs to
> take a base backup or rebuild the replication standby after restarting the server.
And, we expect we can change the wal_level even after using wal_level='none'
and can use other features again like I mentioned above. What did you think ?
Regards,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-10-01 03:58 ` Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: Fujii Masao @ 2020-10-01 03:58 UTC (permalink / raw)
To: [email protected] <[email protected]>; 'Ashutosh Bapat' <[email protected]>; [email protected] <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On 2020/10/01 12:04, [email protected] wrote:
> Hello.
>
>>>> Can they use a database with all unlogged tables?
>>> Unfortunately, no. They want to switch a cluster condition to "without WAL
>> logging"
>>> only when they execute night bulk loading for their data warehouse.
>>> In other words, they would like to keep their other usual operations with WAL.
>>> In addition, using all tables as unlogged brings about the risk to
>>> lose data warehouse's data caused by an unexpected server crash or power
>> outage.
>>
>> But the same issue can happen even in the proposed approach because
>> Tsunakawa-san explains as follows?
> Sorry, my last expression about "to lose data" was not precise.
>
> When unlogged tables are used and the server is crashed unexpectedly,
> all data after the last backup is truncated without WAL, right ?
> In this case, sequential commands for unlogged tables disappear.
To avoid this issue we can mark the table as logged. You may be worried about
that ALTER TABLE SET LOGGED/UNLOGGED would take a long time because
the table needs to be rewriitten. One idea for that is to improve that command
so that it skips the table rewrite if wal_level=minimal.
Of course, also you can change wal_level after marking the table as unlogged.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
@ 2020-10-01 04:38 ` Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: Kyotaro Horiguchi @ 2020-10-01 04:38 UTC (permalink / raw)
To: [email protected]; +Cc: [email protected]; [email protected]; [email protected]; [email protected]
At Thu, 1 Oct 2020 12:58:19 +0900, Fujii Masao <[email protected]> wrote in
> the table needs to be rewriitten. One idea for that is to improve that
> command
> so that it skips the table rewrite if wal_level=minimal.
> Of course, also you can change wal_level after marking the table as
> unlogged.
tablecmd.c:
> * There are two reasons for requiring a rewrite when changing
> * persistence: on one hand, we need to ensure that the buffers
> * belonging to each of the two relations are marked with or without
> * BM_PERMANENT properly. On the other hand, since rewriting creates
> * and assigns a new relfilenode, we automatically create or drop an
> * init fork for the relation as appropriate.
According to this comment, perhaps we can do that at least for
wal_level=minimal.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
@ 2020-10-01 08:14 ` [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-10-01 08:14 UTC (permalink / raw)
To: 'Kyotaro Horiguchi' <[email protected]>; [email protected] <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Hi, Horiguchi-San and Fujii-San.
Thank you so much both of you.
> > the table needs to be rewriitten. One idea for that is to improve that
> > command so that it skips the table rewrite if wal_level=minimal.
> > Of course, also you can change wal_level after marking the table as
> > unlogged.
>
> tablecmd.c:
The idea is really interesting.
I didn't come up with getting rid of the whole copy of
the ALTER TABLE UNLOGGED/LOGGED commands
only when wal_level='minimal'.
> > * There are two reasons for requiring a rewrite when changing
> > * persistence: on one hand, we need to ensure that the buffers
> > * belonging to each of the two relations are marked with or without
> > * BM_PERMANENT properly. On the other hand, since rewriting creates
> > * and assigns a new relfilenode, we automatically create or drop an
> > * init fork for the relation as appropriate.
Thanks for sharing concrete comments in the source code.
> According to this comment, perhaps we can do that at least for
> wal_level=minimal.
When I compare the 2 ideas,
one of the benefits of this ALTER TABLE 's improvement
is that we can't avoid the downtime
while that of wal_level='none' provides an easy and faster
major version up via output file of pg_dumpall.
Both ideas have good points.
However, actually to modify ALTER TABLE's copy
looks far more difficult than wal_level='none' and
beyond my current ability.
So, I'd like to go forward with the direction of wal_level='none'.
Did you have strong objections for this direction ?
Regards,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-10-02 01:06 ` Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-10 14:33 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
0 siblings, 2 replies; 392+ messages in thread
From: Kyotaro Horiguchi @ 2020-10-02 01:06 UTC (permalink / raw)
To: [email protected]; +Cc: [email protected]; [email protected]; [email protected]; [email protected]
At Thu, 1 Oct 2020 08:14:42 +0000, "[email protected]" <[email protected]> wrote in
> Hi, Horiguchi-San and Fujii-San.
>
>
> Thank you so much both of you.
> > > the table needs to be rewriitten. One idea for that is to improve that
> > > command so that it skips the table rewrite if wal_level=minimal.
> > > Of course, also you can change wal_level after marking the table as
> > > unlogged.
> >
> > tablecmd.c:
> The idea is really interesting.
> I didn't come up with getting rid of the whole copy of
> the ALTER TABLE UNLOGGED/LOGGED commands
> only when wal_level='minimal'.
>
> > > * There are two reasons for requiring a rewrite when changing
> > > * persistence: on one hand, we need to ensure that the buffers
> > > * belonging to each of the two relations are marked with or without
> > > * BM_PERMANENT properly. On the other hand, since rewriting creates
> > > * and assigns a new relfilenode, we automatically create or drop an
> > > * init fork for the relation as appropriate.
> Thanks for sharing concrete comments in the source code.
>
> > According to this comment, perhaps we can do that at least for
> > wal_level=minimal.
> When I compare the 2 ideas,
> one of the benefits of this ALTER TABLE 's improvement
> is that we can't avoid the downtime
> while that of wal_level='none' provides an easy and faster
> major version up via output file of pg_dumpall.
The speedup has already been achieved with higher durability by
wal_level=minimal in that case. Or maybe you should consider using
pg_upgrade instead. Even inducing the time to take a backup copy of
the whole cluster, running pg_upgrade would be far faster than
pg_dumpall then loading.
> Both ideas have good points.
> However, actually to modify ALTER TABLE's copy
> looks far more difficult than wal_level='none' and
> beyond my current ability.
> So, I'd like to go forward with the direction of wal_level='none'.
> Did you have strong objections for this direction ?
For fuel(?) of the discussion, I tried a very-quick PoC for in-place
ALTER TABLE SET LOGGED/UNLOGGED and resulted as attached. After some
trials of several ways, I drifted to the following way after poking
several ways.
1. Flip BM_PERMANENT of active buffers
2. adding/removing init fork
3. sync files,
4. Flip pg_class.relpersistence.
It always skips table copy in the SET UNLOGGED case, and only when
wal_level=minimal in the SET LOGGED case. Crash recovery seems
working by some brief testing by hand.
Of course, I haven't performed intensive test on it.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
Attachments:
[text/x-patch] PoC_in-place_set_persistence.patch (19.5K, ../../[email protected]/2-PoC_in-place_set_persistence.patch)
download | inline diff:
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index dcaea7135f..d8a1c2a7e7 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -613,6 +613,26 @@ heapam_relation_set_new_filenode(Relation rel,
smgrclose(srel);
}
+static void
+heapam_relation_set_persistence(Relation rel, char persistence)
+{
+ Assert(rel->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT ||
+ rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED);
+
+ Assert (rel->rd_rel->relpersistence != persistence);
+
+ if (persistence == RELPERSISTENCE_UNLOGGED)
+ {
+ Assert(rel->rd_rel->relkind == RELKIND_RELATION ||
+ rel->rd_rel->relkind == RELKIND_MATVIEW ||
+ rel->rd_rel->relkind == RELKIND_TOASTVALUE);
+ RelationCreateInitFork(rel->rd_node);
+ }
+ else
+ RelationDropInitFork(rel->rd_node);
+}
+
+
static void
heapam_relation_nontransactional_truncate(Relation rel)
{
@@ -2540,6 +2560,7 @@ static const TableAmRoutine heapam_methods = {
.compute_xid_horizon_for_tuples = heap_compute_xid_horizon_for_tuples,
.relation_set_new_filenode = heapam_relation_set_new_filenode,
+ .relation_set_persistence = heapam_relation_set_persistence,
.relation_nontransactional_truncate = heapam_relation_nontransactional_truncate,
.relation_copy_data = heapam_relation_copy_data,
.relation_copy_for_cluster = heapam_relation_copy_for_cluster,
diff --git a/src/backend/access/rmgrdesc/smgrdesc.c b/src/backend/access/rmgrdesc/smgrdesc.c
index a7c0cb1bc3..8397002613 100644
--- a/src/backend/access/rmgrdesc/smgrdesc.c
+++ b/src/backend/access/rmgrdesc/smgrdesc.c
@@ -40,6 +40,14 @@ smgr_desc(StringInfo buf, XLogReaderState *record)
xlrec->blkno, xlrec->flags);
pfree(path);
}
+ else if (info == XLOG_SMGR_UNLINK)
+ {
+ xl_smgr_unlink *xlrec = (xl_smgr_unlink *) rec;
+ char *path = relpathperm(xlrec->rnode, xlrec->forkNum);
+
+ appendStringInfoString(buf, path);
+ pfree(path);
+ }
}
const char *
@@ -55,6 +63,9 @@ smgr_identify(uint8 info)
case XLOG_SMGR_TRUNCATE:
id = "TRUNCATE";
break;
+ case XLOG_SMGR_UNLINK:
+ id = "UNLINK";
+ break;
}
return id;
diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c
index dbbd3aa31f..7f695e6d8b 100644
--- a/src/backend/catalog/storage.c
+++ b/src/backend/catalog/storage.c
@@ -60,6 +60,8 @@ int wal_skip_threshold = 2048; /* in kilobytes */
typedef struct PendingRelDelete
{
RelFileNode relnode; /* relation that may need to be deleted */
+ bool deleteinitfork; /* delete only init fork if true */
+ bool createinitfork; /* create init fork if true */
BackendId backend; /* InvalidBackendId if not a temp rel */
bool atCommit; /* T=delete at commit; F=delete at abort */
int nestLevel; /* xact nesting level of request */
@@ -153,6 +155,8 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence)
pending = (PendingRelDelete *)
MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
pending->relnode = rnode;
+ pending->deleteinitfork = false;
+ pending->createinitfork = false;
pending->backend = backend;
pending->atCommit = false; /* delete if abort */
pending->nestLevel = GetCurrentTransactionNestLevel();
@@ -168,6 +172,53 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence)
return srel;
}
+void
+RelationCreateInitFork(RelFileNode rnode)
+{
+ PendingRelDelete *pending;
+ SMgrRelation srel;
+
+ srel = smgropen(rnode, InvalidBackendId);
+ smgrcreate(srel, INIT_FORKNUM, false);
+ log_smgrcreate(&rnode, INIT_FORKNUM);
+ smgrimmedsync(srel, INIT_FORKNUM);
+
+ /* Add the relation to the list of stuff to delete at abort */
+ pending = (PendingRelDelete *)
+ MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
+ pending->relnode = rnode;
+ pending->deleteinitfork = true;
+ pending->createinitfork = false;
+ pending->backend = InvalidBackendId;
+ pending->atCommit = false; /* delete if abort */
+ pending->nestLevel = GetCurrentTransactionNestLevel();
+ pending->next = pendingDeletes;
+ pendingDeletes = pending;
+}
+
+void
+RelationDropInitFork(RelFileNode rnode)
+{
+ PendingRelDelete *pending;
+ SMgrRelation srel;
+
+ srel = smgropen(rnode, InvalidBackendId);
+ smgrunlink(srel, INIT_FORKNUM, false);
+ log_smgrunlink(&rnode, INIT_FORKNUM);
+
+ /* Add the relation to the list of stuff to delete at abort */
+ pending = (PendingRelDelete *)
+ MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
+ pending->relnode = rnode;
+ pending->deleteinitfork = false;
+ pending->createinitfork = true;
+ pending->backend = InvalidBackendId;
+ pending->atCommit = false; /* create if abort */
+ pending->nestLevel = GetCurrentTransactionNestLevel();
+ pending->next = pendingDeletes;
+ pendingDeletes = pending;
+}
+
/*
* Perform XLogInsert of an XLOG_SMGR_CREATE record to WAL.
*/
@@ -187,6 +238,25 @@ log_smgrcreate(const RelFileNode *rnode, ForkNumber forkNum)
XLogInsert(RM_SMGR_ID, XLOG_SMGR_CREATE | XLR_SPECIAL_REL_UPDATE);
}
+/*
+ * Perform XLogInsert of an XLOG_SMGR_UNLINK record to WAL.
+ */
+void
+log_smgrunlink(const RelFileNode *rnode, ForkNumber forkNum)
+{
+ xl_smgr_unlink xlrec;
+
+ /*
+ * Make an XLOG entry reporting the file unlink.
+ */
+ xlrec.rnode = *rnode;
+ xlrec.forkNum = forkNum;
+
+ XLogBeginInsert();
+ XLogRegisterData((char *) &xlrec, sizeof(xlrec));
+ XLogInsert(RM_SMGR_ID, XLOG_SMGR_UNLINK | XLR_SPECIAL_REL_UPDATE);
+}
+
/*
* RelationDropStorage
* Schedule unlinking of physical storage at transaction commit.
@@ -200,6 +270,8 @@ RelationDropStorage(Relation rel)
pending = (PendingRelDelete *)
MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
pending->relnode = rel->rd_node;
+ pending->createinitfork = false;
+ pending->deleteinitfork = false;
pending->backend = rel->rd_backend;
pending->atCommit = true; /* delete if commit */
pending->nestLevel = GetCurrentTransactionNestLevel();
@@ -625,19 +697,34 @@ smgrDoPendingDeletes(bool isCommit)
srel = smgropen(pending->relnode, pending->backend);
- /* allocate the initial array, or extend it, if needed */
- if (maxrels == 0)
+ /* XXXX */
+ if (pending->createinitfork)
{
- maxrels = 8;
- srels = palloc(sizeof(SMgrRelation) * maxrels);
+ smgrcreate(srel, INIT_FORKNUM, false);
+ log_smgrcreate(&pending->relnode, INIT_FORKNUM);
+ smgrimmedsync(srel, INIT_FORKNUM);
}
- else if (maxrels <= nrels)
+ else if (pending->deleteinitfork)
{
- maxrels *= 2;
- srels = repalloc(srels, sizeof(SMgrRelation) * maxrels);
+ smgrunlink(srel, INIT_FORKNUM, false);
+ log_smgrunlink(&pending->relnode, INIT_FORKNUM);
}
+ else
+ {
+ /* allocate the initial array, or extend it, if needed */
+ if (maxrels == 0)
+ {
+ maxrels = 8;
+ srels = palloc(sizeof(SMgrRelation) * maxrels);
+ }
+ else if (maxrels <= nrels)
+ {
+ maxrels *= 2;
+ srels = repalloc(srels, sizeof(SMgrRelation) * maxrels);
+ }
- srels[nrels++] = srel;
+ srels[nrels++] = srel;
+ }
}
/* must explicitly free the list entry */
pfree(pending);
@@ -916,6 +1003,14 @@ smgr_redo(XLogReaderState *record)
reln = smgropen(xlrec->rnode, InvalidBackendId);
smgrcreate(reln, xlrec->forkNum, true);
}
+ else if (info == XLOG_SMGR_UNLINK)
+ {
+ xl_smgr_unlink *xlrec = (xl_smgr_unlink *) XLogRecGetData(record);
+ SMgrRelation reln;
+
+ reln = smgropen(xlrec->rnode, InvalidBackendId);
+ smgrunlink(reln, xlrec->forkNum, true);
+ }
else if (info == XLOG_SMGR_TRUNCATE)
{
xl_smgr_truncate *xlrec = (xl_smgr_truncate *) XLogRecGetData(record);
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index e0ac4e05e5..fdcdb1dbb1 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -4897,6 +4897,89 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
return newcmd;
}
+static bool
+try_inplace_persistence_change(AlteredTableInfo *tab, char persistence,
+ LOCKMODE lockmode)
+{
+ Relation rel;
+ Relation classRel;
+ HeapTuple tuple,
+ newtuple;
+ Datum new_val[Natts_pg_class];
+ bool new_null[Natts_pg_class],
+ new_repl[Natts_pg_class];
+ int i;
+
+ Assert(tab->rewrite == AT_REWRITE_ALTER_PERSISTENCE);
+ Assert(lockmode == AccessExclusiveLock);
+
+ /*
+ * Under the following condition, we need to call ATRewriteTable, but
+ * cannot be false in the AT_REWRITE_ALTER_PERSISTENCE case.
+ */
+ Assert(tab->constraints == NULL && tab->partition_constraint == NULL &&
+ tab->newvals == NULL && !tab->verify_new_notnull);
+
+ /*
+ * In the case of SET ULOGGED, the resulting relation does not need WALs,
+ * so the storage can be used as-is. In the opposite case, the table is
+ * required to be restored from WAL, so rewrite the relation. However,
+ * when wal_level = minimal, we can omit WALs by immediately syncing the
+ * storage.
+ */
+ if (tab->newrelpersistence == RELPERSISTENCE_PERMANENT || XLogIsNeeded())
+ return false;
+
+ rel = table_open(tab->relid, lockmode);
+
+ Assert(rel->rd_rel->relpersistence != persistence);
+
+ elog(DEBUG1, "perform im-place persistnce change");
+
+ RelationOpenSmgr(rel);
+ SetRelFileNodeBuffersPersistence(rel->rd_smgr->smgr_rnode,
+ persistence == RELPERSISTENCE_PERMANENT);
+ table_relation_set_persistence(rel, persistence);
+
+ /*
+ * This relation is now WAL-logged. Sync all files immediately to establish
+ * the initial state.
+ */
+ if (persistence == RELPERSISTENCE_PERMANENT)
+ {
+ for (i = 0 ; i < MAX_FORKNUM ; i++)
+ {
+ if (smgrexists(rel->rd_smgr, i))
+ smgrimmedsync(rel->rd_smgr, i);
+ }
+ }
+
+ table_close(rel, lockmode);
+ classRel = table_open(RelationRelationId, RowExclusiveLock);
+ tuple = SearchSysCacheCopy1(RELOID,
+ ObjectIdGetDatum(RelationGetRelid(rel)));
+ if (!HeapTupleIsValid(tuple))
+ elog(ERROR, "cache lookup failed for relation %u",
+ RelationGetRelid(rel));
+
+ memset(new_val, 0, sizeof(new_val));
+ memset(new_null, false, sizeof(new_null));
+ memset(new_repl, false, sizeof(new_repl));
+
+ new_val[Anum_pg_class_relpersistence - 1] = CharGetDatum(persistence);
+ new_null[Anum_pg_class_relpersistence - 1] = false;
+ new_repl[Anum_pg_class_relpersistence - 1] = true;
+
+ newtuple = heap_modify_tuple(tuple, RelationGetDescr(classRel),
+ new_val, new_null, new_repl);
+
+ CatalogTupleUpdate(classRel, &newtuple->t_self, newtuple);
+ heap_freetuple(newtuple);
+ table_close(classRel, RowExclusiveLock);
+
+ return true;
+}
+
/*
* ATRewriteTables: ALTER TABLE phase 3
*/
@@ -5017,45 +5100,51 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode,
tab->relid,
tab->rewrite);
- /*
- * Create transient table that will receive the modified data.
- *
- * Ensure it is marked correctly as logged or unlogged. We have
- * to do this here so that buffers for the new relfilenode will
- * have the right persistence set, and at the same time ensure
- * that the original filenode's buffers will get read in with the
- * correct setting (i.e. the original one). Otherwise a rollback
- * after the rewrite would possibly result with buffers for the
- * original filenode having the wrong persistence setting.
- *
- * NB: This relies on swap_relation_files() also swapping the
- * persistence. That wouldn't work for pg_class, but that can't be
- * unlogged anyway.
- */
- OIDNewHeap = make_new_heap(tab->relid, NewTableSpace, persistence,
- lockmode);
+ if (tab->rewrite != AT_REWRITE_ALTER_PERSISTENCE ||
+ !try_inplace_persistence_change(tab, persistence, lockmode))
+ {
+ /*
+ * Create transient table that will receive the modified data.
+ *
+ * Ensure it is marked correctly as logged or unlogged. We
+ * have to do this here so that buffers for the new relfilenode
+ * will have the right persistence set, and at the same time
+ * ensure that the original filenode's buffers will get read in
+ * with the correct setting (i.e. the original one). Otherwise
+ * a rollback after the rewrite would possibly result with
+ * buffers for the original filenode having the wrong
+ * persistence setting.
+ *
+ * NB: This relies on swap_relation_files() also swapping the
+ * persistence. That wouldn't work for pg_class, but that can't
+ * be unlogged anyway.
+ */
+ OIDNewHeap = make_new_heap(tab->relid, NewTableSpace, persistence,
+ lockmode);
- /*
- * Copy the heap data into the new table with the desired
- * modifications, and test the current data within the table
- * against new constraints generated by ALTER TABLE commands.
- */
- ATRewriteTable(tab, OIDNewHeap, lockmode);
+ /*
+ * Copy the heap data into the new table with the desired
+ * modifications, and test the current data within the table
+ * against new constraints generated by ALTER TABLE commands.
+ */
+ ATRewriteTable(tab, OIDNewHeap, lockmode);
- /*
- * Swap the physical files of the old and new heaps, then rebuild
- * indexes and discard the old heap. We can use RecentXmin for
- * the table's new relfrozenxid because we rewrote all the tuples
- * in ATRewriteTable, so no older Xid remains in the table. Also,
- * we never try to swap toast tables by content, since we have no
- * interest in letting this code work on system catalogs.
- */
- finish_heap_swap(tab->relid, OIDNewHeap,
- false, false, true,
- !OidIsValid(tab->newTableSpace),
- RecentXmin,
- ReadNextMultiXactId(),
- persistence);
+ /*
+ * Swap the physical files of the old and new heaps, then
+ * rebuild indexes and discard the old heap. We can use
+ * RecentXmin for the table's new relfrozenxid because we
+ * rewrote all the tuples in ATRewriteTable, so no older Xid
+ * remains in the table. Also, we never try to swap toast
+ * tables by content, since we have no interest in letting this
+ * code work on system catalogs.
+ */
+ finish_heap_swap(tab->relid, OIDNewHeap,
+ false, false, true,
+ !OidIsValid(tab->newTableSpace),
+ RecentXmin,
+ ReadNextMultiXactId(),
+ persistence);
+ }
}
else
{
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index e549fa1d30..7fd6cae12f 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -3031,6 +3031,40 @@ DropRelFileNodeBuffers(RelFileNodeBackend rnode, ForkNumber *forkNum,
}
}
+void
+SetRelFileNodeBuffersPersistence(RelFileNodeBackend rnode, bool permanent)
+{
+ int i;
+
+ Assert (!RelFileNodeBackendIsTemp(rnode));
+
+ for (i = 0; i < NBuffers; i++)
+ {
+ BufferDesc *bufHdr = GetBufferDescriptor(i);
+ uint32 buf_state;
+
+ if (!RelFileNodeEquals(bufHdr->tag.rnode, rnode.node))
+ continue;
+
+ buf_state = LockBufHdr(bufHdr);
+
+ if (RelFileNodeEquals(bufHdr->tag.rnode, rnode.node))
+ {
+ if (permanent)
+ {
+ Assert ((buf_state & BM_PERMANENT) == 0);
+ buf_state |= BM_PERMANENT;
+ }
+ else
+ {
+ Assert ((buf_state & BM_PERMANENT) != 0);
+ buf_state &= ~BM_PERMANENT;
+ }
+ }
+ UnlockBufHdr(bufHdr, buf_state);
+ }
+}
+
/* ---------------------------------------------------------------------
* DropRelFileNodesAllBuffers
*
diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c
index dcc09df0c7..5eb9e97b3d 100644
--- a/src/backend/storage/smgr/smgr.c
+++ b/src/backend/storage/smgr/smgr.c
@@ -645,6 +645,12 @@ smgrimmedsync(SMgrRelation reln, ForkNumber forknum)
smgrsw[reln->smgr_which].smgr_immedsync(reln, forknum);
}
+void
+smgrunlink(SMgrRelation reln, ForkNumber forknum, bool isRedo)
+{
+ smgrsw[reln->smgr_which].smgr_unlink(reln->smgr_rnode, forknum, isRedo);
+}
+
/*
* AtEOXact_SMgr
*
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 387eb34a61..245a8f0fdd 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -451,6 +451,8 @@ typedef struct TableAmRoutine
TransactionId *freezeXid,
MultiXactId *minmulti);
+ void (*relation_set_persistence) (Relation rel, char persistence);
+
/*
* This callback needs to remove all contents from `rel`'s current
* relfilenode. No provisions for transactional behaviour need to be made.
@@ -1404,6 +1406,12 @@ table_relation_set_new_filenode(Relation rel,
freezeXid, minmulti);
}
+static inline void
+table_relation_set_persistence(Relation rel, char persistence)
+{
+ rel->rd_tableam->relation_set_persistence(rel, persistence);
+}
+
/*
* Remove all table contents from `rel`, in a non-transactional manner.
* Non-transactional meaning that there's no need to support rollbacks. This
diff --git a/src/include/catalog/storage.h b/src/include/catalog/storage.h
index 30c38e0ca6..f4fd61f639 100644
--- a/src/include/catalog/storage.h
+++ b/src/include/catalog/storage.h
@@ -23,6 +23,8 @@
extern int wal_skip_threshold;
extern SMgrRelation RelationCreateStorage(RelFileNode rnode, char relpersistence);
+extern void RelationCreateInitFork(RelFileNode rel);
+extern void RelationDropInitFork(RelFileNode rel);
extern void RelationDropStorage(Relation rel);
extern void RelationPreserveStorage(RelFileNode rnode, bool atCommit);
extern void RelationPreTruncate(Relation rel);
diff --git a/src/include/catalog/storage_xlog.h b/src/include/catalog/storage_xlog.h
index 7b21cab2e0..73ad2ae89e 100644
--- a/src/include/catalog/storage_xlog.h
+++ b/src/include/catalog/storage_xlog.h
@@ -29,6 +29,7 @@
/* XLOG gives us high 4 bits */
#define XLOG_SMGR_CREATE 0x10
#define XLOG_SMGR_TRUNCATE 0x20
+#define XLOG_SMGR_UNLINK 0x30
typedef struct xl_smgr_create
{
@@ -36,6 +37,12 @@ typedef struct xl_smgr_create
ForkNumber forkNum;
} xl_smgr_create;
+typedef struct xl_smgr_unlink
+{
+ RelFileNode rnode;
+ ForkNumber forkNum;
+} xl_smgr_unlink;
+
/* flags for xl_smgr_truncate */
#define SMGR_TRUNCATE_HEAP 0x0001
#define SMGR_TRUNCATE_VM 0x0002
@@ -51,6 +58,7 @@ typedef struct xl_smgr_truncate
} xl_smgr_truncate;
extern void log_smgrcreate(const RelFileNode *rnode, ForkNumber forkNum);
+extern void log_smgrunlink(const RelFileNode *rnode, ForkNumber forkNum);
extern void smgr_redo(XLogReaderState *record);
extern void smgr_desc(StringInfo buf, XLogReaderState *record);
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h
index ee91b8fa26..98967eeff9 100644
--- a/src/include/storage/bufmgr.h
+++ b/src/include/storage/bufmgr.h
@@ -205,6 +205,8 @@ extern void FlushRelationsAllBuffers(struct SMgrRelationData **smgrs, int nrels)
extern void FlushDatabaseBuffers(Oid dbid);
extern void DropRelFileNodeBuffers(RelFileNodeBackend rnode, ForkNumber *forkNum,
int nforks, BlockNumber *firstDelBlock);
+extern void SetRelFileNodeBuffersPersistence(RelFileNodeBackend rnode,
+ bool permanent);
extern void DropRelFileNodesAllBuffers(RelFileNodeBackend *rnodes, int nnodes);
extern void DropDatabaseBuffers(Oid dbid);
diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h
index f28a842401..5d74631006 100644
--- a/src/include/storage/smgr.h
+++ b/src/include/storage/smgr.h
@@ -86,6 +86,7 @@ extern void smgrclose(SMgrRelation reln);
extern void smgrcloseall(void);
extern void smgrclosenode(RelFileNodeBackend rnode);
extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
+extern void smgrunlink(SMgrRelation reln, ForkNumber forknum, bool isRedo);
extern void smgrdosyncall(SMgrRelation *rels, int nrels);
extern void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo);
extern void smgrextend(SMgrRelation reln, ForkNumber forknum,
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
@ 2020-10-02 01:56 ` Fujii Masao <[email protected]>
2020-10-02 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 2 replies; 392+ messages in thread
From: Fujii Masao @ 2020-10-02 01:56 UTC (permalink / raw)
To: Kyotaro Horiguchi <[email protected]>; [email protected]; +Cc: [email protected]; [email protected]; [email protected]
On 2020/10/02 10:06, Kyotaro Horiguchi wrote:
> At Thu, 1 Oct 2020 08:14:42 +0000, "[email protected]" <[email protected]> wrote in
>> Hi, Horiguchi-San and Fujii-San.
>>
>>
>> Thank you so much both of you.
>>>> the table needs to be rewriitten. One idea for that is to improve that
>>>> command so that it skips the table rewrite if wal_level=minimal.
>>>> Of course, also you can change wal_level after marking the table as
>>>> unlogged.
>>>
>>> tablecmd.c:
>> The idea is really interesting.
>> I didn't come up with getting rid of the whole copy of
>> the ALTER TABLE UNLOGGED/LOGGED commands
>> only when wal_level='minimal'.
>>
>>>> * There are two reasons for requiring a rewrite when changing
>>>> * persistence: on one hand, we need to ensure that the buffers
>>>> * belonging to each of the two relations are marked with or without
>>>> * BM_PERMANENT properly. On the other hand, since rewriting creates
>>>> * and assigns a new relfilenode, we automatically create or drop an
>>>> * init fork for the relation as appropriate.
>> Thanks for sharing concrete comments in the source code.
>>
>>> According to this comment, perhaps we can do that at least for
>>> wal_level=minimal.
>> When I compare the 2 ideas,
>> one of the benefits of this ALTER TABLE 's improvement
>> is that we can't avoid the downtime
>> while that of wal_level='none' provides an easy and faster
>> major version up via output file of pg_dumpall.
>
> The speedup has already been achieved with higher durability by
> wal_level=minimal in that case.
I was thinking the same, i.e., wal_level=minimal + wal_skip_threshold would
speed up that initial data loading.
> Or maybe you should consider using
> pg_upgrade instead. Even inducing the time to take a backup copy of
> the whole cluster, running pg_upgrade would be far faster than
> pg_dumpall then loading.
>
>> Both ideas have good points.
>> However, actually to modify ALTER TABLE's copy
>> looks far more difficult than wal_level='none' and
>> beyond my current ability.
>> So, I'd like to go forward with the direction of wal_level='none'.
>> Did you have strong objections for this direction ?
No, I have no strong objection against your trial. But I was thinking
that it's not so easy to design and implement wal_level=none.
For example, there are some functions and commands depending on
the existence of WAL, like pg_switch_wal(), PREPARE TRANSACTION
and COMMIT PREPARED. Probably you need to define how they should
work in wal_level=none, e.g., emit an error.
> For fuel(?) of the discussion, I tried a very-quick PoC for in-place
> ALTER TABLE SET LOGGED/UNLOGGED and resulted as attached. After some
> trials of several ways, I drifted to the following way after poking
> several ways.
Nice!
> 1. Flip BM_PERMANENT of active buffers
> 2. adding/removing init fork
> 3. sync files,
> 4. Flip pg_class.relpersistence.
>
> It always skips table copy in the SET UNLOGGED case,
Even in wal_level != minimal?
What happens in the standby side when SET UNLOGGED is executed without
the table rewrite in the primary? The table data should be truncated
in the standby?
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
@ 2020-10-02 04:38 ` Kyotaro Horiguchi <[email protected]>
2020-10-02 04:51 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: Kyotaro Horiguchi @ 2020-10-02 04:38 UTC (permalink / raw)
To: [email protected]; +Cc: [email protected]; [email protected]; [email protected]; [email protected]
At Fri, 2 Oct 2020 10:56:21 +0900, Fujii Masao <[email protected]> wrote in
>
> On 2020/10/02 10:06, Kyotaro Horiguchi wrote:
> > At Thu, 1 Oct 2020 08:14:42 +0000, "[email protected]"
> > <[email protected]> wrote in
> >> When I compare the 2 ideas,
> >> one of the benefits of this ALTER TABLE 's improvement
> >> is that we can't avoid the downtime
> >> while that of wal_level='none' provides an easy and faster
> >> major version up via output file of pg_dumpall.
> > The speedup has already been achieved with higher durability by
> > wal_level=minimal in that case.
>
> I was thinking the same, i.e., wal_level=minimal + wal_skip_threshold
> would
> speed up that initial data loading.
Yeah.
> > Or maybe you should consider using
> > pg_upgrade instead. Even inducing the time to take a backup copy of
> > the whole cluster, running pg_upgrade would be far faster than
> > pg_dumpall then loading.
> >
> >> Both ideas have good points.
> >> However, actually to modify ALTER TABLE's copy
> >> looks far more difficult than wal_level='none' and
> >> beyond my current ability.
> >> So, I'd like to go forward with the direction of wal_level='none'.
> >> Did you have strong objections for this direction ?
>
> No, I have no strong objection against your trial. But I was thinking
> that it's not so easy to design and implement wal_level=none.
> For example, there are some functions and commands depending on
> the existence of WAL, like pg_switch_wal(), PREPARE TRANSACTION
> and COMMIT PREPARED. Probably you need to define how they should
> work in wal_level=none, e.g., emit an error.
>
>
> > For fuel(?) of the discussion, I tried a very-quick PoC for in-place
> > ALTER TABLE SET LOGGED/UNLOGGED and resulted as attached. After some
> > trials of several ways, I drifted to the following way after poking
> > several ways.
>
> Nice!
>
>
> > 1. Flip BM_PERMANENT of active buffers
> > 2. adding/removing init fork
> > 3. sync files,
> > 4. Flip pg_class.relpersistence.
> > It always skips table copy in the SET UNLOGGED case,
>
> Even in wal_level != minimal?
> What happens in the standby side when SET UNLOGGED is executed without
> the table rewrite in the primary? The table data should be truncated
> in the standby?
A table turned into unlogged on the primary is also turned into
unlogged on the standby and it is inaccessible on the standby. Maybe
the storage is dropped on both patched and unpatched versoins.
After the table is again turned into logged, the content is
transferred via WAL records generated from the insertions into the new
storage and it rebuilds the same storage on the standby on both
patched and unpatched.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
@ 2020-10-02 04:51 ` Kyotaro Horiguchi <[email protected]>
2020-10-02 05:07 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: Kyotaro Horiguchi @ 2020-10-02 04:51 UTC (permalink / raw)
To: [email protected]; +Cc: [email protected]; [email protected]; [email protected]; [email protected]
Sorry for the slippery brain...
At Fri, 02 Oct 2020 13:38:22 +0900 (JST), Kyotaro Horiguchi <[email protected]> wrote in
> At Fri, 2 Oct 2020 10:56:21 +0900, Fujii Masao <[email protected]> wrote in
> >
> > On 2020/10/02 10:06, Kyotaro Horiguchi wrote:
> > > 1. Flip BM_PERMANENT of active buffers
> > > 2. adding/removing init fork
> > > 3. sync files,
> > > 4. Flip pg_class.relpersistence.
> > > It always skips table copy in the SET UNLOGGED case,
> >
> > Even in wal_level != minimal?
> > What happens in the standby side when SET UNLOGGED is executed without
> > the table rewrite in the primary? The table data should be truncated
> > in the standby?
>
> A table turned into unlogged on the primary is also turned into
> unlogged on the standby and it is inaccessible on the standby.
> Maybe the storage is dropped on both patched and unpatched versoins.
Maybe the storage dropped on unpatched and left alone on patched.
> After the table is again turned into logged, the content is
> transferred via WAL records generated from the insertions into the new
> storage and it rebuilds the same storage on the standby on both
> patched and unpatched.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 04:51 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
@ 2020-10-02 05:07 ` Kyotaro Horiguchi <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Kyotaro Horiguchi @ 2020-10-02 05:07 UTC (permalink / raw)
To: [email protected]; +Cc: [email protected]; [email protected]; [email protected]; [email protected]
At Fri, 02 Oct 2020 13:51:35 +0900 (JST), Kyotaro Horiguchi <[email protected]> wrote in
> Sorry for the slippery brain... ^2
> At Fri, 02 Oct 2020 13:38:22 +0900 (JST), Kyotaro Horiguchi <[email protected]> wrote in
> > At Fri, 2 Oct 2020 10:56:21 +0900, Fujii Masao <[email protected]> wrote in
> > >
> > > On 2020/10/02 10:06, Kyotaro Horiguchi wrote:
> > > > 1. Flip BM_PERMANENT of active buffers
> > > > 2. adding/removing init fork
> > > > 3. sync files,
> > > > 4. Flip pg_class.relpersistence.
> > > > It always skips table copy in the SET UNLOGGED case,
> > >
> > > Even in wal_level != minimal?
> > > What happens in the standby side when SET UNLOGGED is executed without
> > > the table rewrite in the primary? The table data should be truncated
> > > in the standby?
> >
> > A table turned into unlogged on the primary is also turned into
> > unlogged on the standby and it is inaccessible on the standby.
> Maybe the storage dropped on unpatched
Maybe the old storage is replaced with an empty stroage on unpatched.
> and left alone on patched.
> > After the table is again turned into logged, the content is
> > transferred via WAL records generated from the insertions into the new
> > storage and it rebuilds the same storage on the standby on both
> > patched and unpatched.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
@ 2020-10-02 05:03 ` [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-10-02 05:03 UTC (permalink / raw)
To: 'Fujii Masao' <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
From: Fujii Masao <[email protected]>
> > The speedup has already been achieved with higher durability by
> > wal_level=minimal in that case.
>
> I was thinking the same, i.e., wal_level=minimal + wal_skip_threshold would
> speed up that initial data loading.
First of all, thank you Horiguchi-san for trying to improve ALTER TABLE SET UNLOGGED/LOGGED. That should also be appealing.
At the same time, as I said before, both features have good points. TBH, as a user, I'm kind of attracted by MySQL's approach because of its simplicity for users (although DBMS developers may be worried about this and that.) What tempts me is that I can just switch on the feature with a single configuration parameter, and continue to use existing SQL scripts and other data integration software without knowing what tables those load data into. In the same context, I don't have to add or delete ALTER TABLE statements when I have to change the set of tables to be loaded. For the same reason, I'm also interested in Oracle's another feature ALTER TABLESPACE LOGGING/NOLOGGING.
BTW, does ALTER TABLE LOGGED/UNLOGGED on a partitioned table get the change to its all partitions? It would be a bit tedious to add/delete ALTER TABLE LOGGED/UNLOGGED when I add/drop a partition.
Regarding data migration, data movement is not limited only to major upgrades. It will be convenient to speed up the migration of the entire database cluster into a new instance for testing and new deployment. (I'm not sure about recent pg_upgrade, but pg_upgrade sometimes cannot upgrade too older versions.)
To conclude, I hope both features will be realized, and wish we won't fall in a situation where the words fly such as "Mine is enough. Yours is risky and not necessary."
With that said, I think we may as well separate the thread some time later for CF entry. Otherwise, we will have trouble in finding the latest patch from the CF entry.
> No, I have no strong objection against your trial. But I was thinking
> that it's not so easy to design and implement wal_level=none.
> For example, there are some functions and commands depending on
> the existence of WAL, like pg_switch_wal(), PREPARE TRANSACTION
> and COMMIT PREPARED. Probably you need to define how they should
> work in wal_level=none, e.g., emit an error.
Yeah, we thought pg_switch_wal() may need some treatment. We'll check PREPARE and COMMIT PREPARED as well. I'd appreciate it if you share what you notice at any time. It is possible that we should emit WAL records of some resource managers, like the bootstrap mode emits WAL only for RM_XLOG_ID.
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-10-28 04:11 ` [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 08:46 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
0 siblings, 2 replies; 392+ messages in thread
From: [email protected] @ 2020-10-28 04:11 UTC (permalink / raw)
To: [email protected] <[email protected]>; 'Fujii Masao' <[email protected]>; Kyotaro Horiguchi <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
Hi,
I wrote and attached the first patch to disable WAL logging.
This patch passes the regression test of check-world already
and is formatted by pgindent.
Also, I conducted 3 types of performance tests to
clarify the rough benefits of the patch.
I compared two wal_levels both 'minimal' and 'none'.
For both levels, I measured
(1) cluster's restore from pg_dumpall output,
(2) COPY initial data to a defined table as initial data loading, and
(3) COPY data to a defined table with tuples, 3 times each for all cases.
After that, calculated the average and the ratio of the loading speed.
The conclusion is that wal_level=none cuts about 20% of the loading speed
compared to 'minimal' in the three cases above. For sure, we could tune the configuration of
postgresql.conf further but roughly it's meaningful to share the result, I think.
'shared_buffers' was set to 40% of RAM while 'maintenance_work_mem'
was set to 20%. I set max_wal_senders = 0 this time.
The input data was generated from pgbench with 1000 scale factor.
It's about 9.3GB. For the table definition or
the initial data for appended data loading test case,
I used pgbench to set up the schema as well.
Sharing other scenario to measure is welcome.
I need to say that the current patch doesn't take the change of wal_level='none'
from/to other ones into account fully or other commands like ones for two phase commit yet.
Sorry for that.
Also, to return the value of last shut down LSN in XLogInsert(),
it acquires lock of control file every time, which was not good clearly.
I tried to replace that code like having a LSN cache as one variable
but I was not sure where I should put the function to set the initial value of the LSN.
After LocalProcessControlFile() in PostmasterMain() was not the right place.
I'd be happy if someone gives me an advice about it.
Best,
Takamichi Osumi
Attachments:
[application/octet-stream] disable_WAL_logging_v01.patch (9.1K, ../../OSBPR01MB48882B8D091CE688C4DE2731ED170@OSBPR01MB4888.jpnprd01.prod.outlook.com/2-disable_WAL_logging_v01.patch)
download | inline diff:
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index f043433..e01e002 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -2591,10 +2591,10 @@ include_dir 'conf.d'
data to support WAL archiving and replication, including running
read-only queries on a standby server. <literal>minimal</literal> removes all
logging except the information required to recover from a crash or
- immediate shutdown. Finally,
+ immediate shutdown. <literal>none</literal> generates no WAL in any case. Finally,
<literal>logical</literal> adds information necessary to support logical
- decoding. Each level includes the information logged at all lower
- levels. This parameter can only be set at server start.
+ decoding. Each level except for <literal>none</literal> includes the
+ information logged at all lower levels. This parameter can only be set at server start.
</para>
<para>
In <literal>minimal</literal> level, no information is logged for
@@ -2615,6 +2615,13 @@ include_dir 'conf.d'
data from a base backup and the WAL logs, so <literal>replica</literal> or
higher must be used to enable WAL archiving
(<xref linkend="guc-archive-mode"/>) and streaming replication.
+ In the same way, <literal>none</literal> does not create WAL logs.
+ Therefore, this <varname>wal_level</varname> can be used to maximize the speed of data loading.
+ For example, bulk loading into a data warehouse environemnt or version upgrade using pg_dumpall.
+ On the other hand, an unexpected crash of the server makes the database cluster
+ inconsistent. For that reason, before utilizing this level, get a full backup of the cluster and
+ backup of the entire operations that are done under the condition that
+ <varname>wal_level</varname> is <literal>none</literal>.
</para>
<para>
In <literal>logical</literal> level, the same information is logged as
@@ -3372,7 +3379,8 @@ include_dir 'conf.d'
changed without leaving archiving mode.
This parameter can only be set at server start.
<varname>archive_mode</varname> cannot be enabled when
- <varname>wal_level</varname> is set to <literal>minimal</literal>.
+ <varname>wal_level</varname> is set to <literal>none</literal> or
+ <literal>minimal</literal>.
</para>
</listitem>
</varlistentry>
diff --git a/doc/src/sgml/perform.sgml b/doc/src/sgml/perform.sgml
index 117a1f7..f035c84 100644
--- a/doc/src/sgml/perform.sgml
+++ b/doc/src/sgml/perform.sgml
@@ -1741,7 +1741,8 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
new base backup after the load has completed than to process a large
amount of incremental WAL data. To prevent incremental WAL logging
while loading, disable archiving and streaming replication, by setting
- <xref linkend="guc-wal-level"/> to <literal>minimal</literal>,
+ <xref linkend="guc-wal-level"/> to either <literal>none</literal>
+ or <literal>minimal</literal>,
<xref linkend="guc-archive-mode"/> to <literal>off</literal>, and
<xref linkend="guc-max-wal-senders"/> to zero.
But note that changing these settings requires a server restart.
@@ -1751,7 +1752,8 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
Aside from avoiding the time for the archiver or WAL sender to process the
WAL data, doing this will actually make certain commands faster, because
they do not to write WAL at all if <varname>wal_level</varname>
- is <literal>minimal</literal> and the current subtransaction (or top-level
+ is either <literal>minimal</literal> or <literal>minimal</literal>
+ and the current subtransaction (or top-level
transaction) created or truncated the table or index they change. (They
can guarantee crash safety more cheaply by doing
an <function>fsync</function> at the end than by writing WAL.)
diff --git a/src/backend/access/rmgrdesc/xlogdesc.c b/src/backend/access/rmgrdesc/xlogdesc.c
index 3200f77..8293b3b 100644
--- a/src/backend/access/rmgrdesc/xlogdesc.c
+++ b/src/backend/access/rmgrdesc/xlogdesc.c
@@ -25,6 +25,7 @@
* GUC support
*/
const struct config_enum_entry wal_level_options[] = {
+ {"none", WAL_LEVEL_NONE, false},
{"minimal", WAL_LEVEL_MINIMAL, false},
{"replica", WAL_LEVEL_REPLICA, false},
{"archive", WAL_LEVEL_REPLICA, true}, /* deprecated */
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 52a67b1..4a5e43b 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4907,6 +4907,27 @@ UpdateControlFile(void)
}
/*
+ * Perform an inspection of wal_level='none'.
+ */
+void
+SafelyFinishedNoneLevel(void)
+{
+ bool unexpected_shutdown;
+
+ /*
+ * Detect if we previously crashed under wal_level='none' or not.
+ */
+ unexpected_shutdown = ControlFile->state != DB_SHUTDOWNED &&
+ ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY;
+ if ((ControlFile->wal_level == WAL_LEVEL_NONE && unexpected_shutdown))
+ {
+ ereport(ERROR,
+ (errmsg("Server was unexpectedly shut down when WAL logging was disabled"),
+ errhint("It looks like you need to deploy a new cluster from your full backup again.")));
+ }
+}
+
+/*
* Returns the unique system identifier from control file.
*/
uint64
@@ -4937,6 +4958,21 @@ DataChecksumsEnabled(void)
}
/*
+ * Returns the latest LSN.
+ */
+XLogRecPtr
+GetLatestCheckPointLSN(void)
+{
+ XLogRecPtr latestLSN;
+
+ LWLockAcquire(ControlFileLock, LW_SHARED);
+ latestLSN = ControlFile->checkPoint;
+ LWLockRelease(ControlFileLock);
+
+ return latestLSN;
+}
+
+/*
* Returns a fake LSN for unlogged relations.
*
* Each call generates an LSN that is greater than any previous value
diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c
index 1f0e4e0..39765ad 100644
--- a/src/backend/access/transam/xloginsert.c
+++ b/src/backend/access/transam/xloginsert.c
@@ -449,6 +449,13 @@ XLogInsert(RmgrId rmid, uint8 info)
return EndPos;
}
+ /* Issues WAL only for transaction end and check point */
+ if (wal_level == WAL_LEVEL_NONE && rmid != RM_XLOG_ID)
+ {
+ XLogResetInsertion();
+ return GetLatestCheckPointLSN();
+ }
+
do
{
XLogRecPtr RedoRecPtr;
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 959e3b8..a365cbf 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -918,10 +918,13 @@ PostmasterMain(int argc, char *argv[])
ReservedBackends, MaxConnections);
ExitPostmaster(1);
}
- if (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level == WAL_LEVEL_MINIMAL)
+ if ((XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level == WAL_LEVEL_NONE) ||
+ (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level == WAL_LEVEL_MINIMAL))
ereport(ERROR,
- (errmsg("WAL archival cannot be enabled when wal_level is \"minimal\"")));
- if (max_wal_senders > 0 && wal_level == WAL_LEVEL_MINIMAL)
+ (errmsg("WAL archival cannot be enabled when wal_level is \"%s\"",
+ wal_level == WAL_LEVEL_MINIMAL ? "minimal" : "none")));
+ if ((max_wal_senders > 0 && wal_level == WAL_LEVEL_NONE) ||
+ (max_wal_senders > 0 && wal_level == WAL_LEVEL_MINIMAL))
ereport(ERROR,
(errmsg("WAL streaming (max_wal_senders > 0) requires wal_level \"replica\" or \"logical\"")));
@@ -989,6 +992,12 @@ PostmasterMain(int argc, char *argv[])
LocalProcessControlFile(false);
/*
+ * Check some conditions specific to wal_level='none' and ensures the
+ * database isn't inconsistent.
+ */
+ SafelyFinishedNoneLevel();
+
+ /*
* Register the apply launcher. Since it registers a background worker,
* it needs to be called before InitializeMaxBackends(), and it's probably
* a good idea to call it before any modules had chance to take the
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 3e00ac0..90ec0dc 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -74,6 +74,8 @@ wal_level_str(WalLevel wal_level)
{
switch (wal_level)
{
+ case WAL_LEVEL_NONE:
+ return "none";
case WAL_LEVEL_MINIMAL:
return "minimal";
case WAL_LEVEL_REPLICA:
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 221af87..e21b3cc 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -161,7 +161,8 @@ extern int XLogArchiveMode;
/* WAL levels */
typedef enum WalLevel
{
- WAL_LEVEL_MINIMAL = 0,
+ WAL_LEVEL_NONE = 0,
+ WAL_LEVEL_MINIMAL,
WAL_LEVEL_REPLICA,
WAL_LEVEL_LOGICAL
} WalLevel;
@@ -316,9 +317,11 @@ extern TimestampTz GetLatestXTime(void);
extern TimestampTz GetCurrentChunkReplayStartTime(void);
extern void UpdateControlFile(void);
+extern void SafelyFinishedNoneLevel(void);
extern uint64 GetSystemIdentifier(void);
extern char *GetMockAuthenticationNonce(void);
extern bool DataChecksumsEnabled(void);
+extern XLogRecPtr GetLatestCheckPointLSN(void);
extern XLogRecPtr GetFakeLSNForUnloggedRel(void);
extern Size XLOGShmemSize(void);
extern void XLOGShmemInit(void);
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-10-28 07:18 ` Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: Laurenz Albe @ 2020-10-28 07:18 UTC (permalink / raw)
To: [email protected] <[email protected]>; [email protected] <[email protected]>; 'Fujii Masao' <[email protected]>; Kyotaro Horiguchi <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
On Wed, 2020-10-28 at 04:11 +0000, [email protected] wrote:
> I wrote and attached the first patch to disable WAL logging.
> This patch passes the regression test of check-world already
> and is formatted by pgindent.
Without reading the code, I have my doubts about that feature.
While it clearly will improve performance, it opens the door to
data loss. People will use it to speed up their data loads and
then be unhappy if they cannot use their backups to recover from
a problem.
What happens if you try to do archive recovery across a time where
wal_level was "none"? Will the recovery process fail, as it should,
or will you end up with data corruption?
We already have a performance-related footgun in the shape of
fsync = off. Do we want to add another one?
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
@ 2020-10-28 09:55 ` [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-10-28 09:55 UTC (permalink / raw)
To: 'Laurenz Albe' <[email protected]>; [email protected] <[email protected]>; 'Fujii Masao' <[email protected]>; Kyotaro Horiguchi <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
Hi, Laurenz
> > I wrote and attached the first patch to disable WAL logging.
> > This patch passes the regression test of check-world already and is
> > formatted by pgindent.
>
> Without reading the code, I have my doubts about that feature.
>
> While it clearly will improve performance, it opens the door to data loss.
Therefore, this feature must avoid that
that kind of inconsistent server starts up again.
This has been discussed in this thread already.
> People will use it to speed up their data loads and then be unhappy if they
> cannot use their backups to recover from a problem.
>
> What happens if you try to do archive recovery across a time where wal_level
> was "none"? Will the recovery process fail, as it should, or will you end up
> with data corruption?
>
> We already have a performance-related footgun in the shape of fsync = off.
> Do we want to add another one?
Further, in this thread, we discuss that
this feature is intended to serve under
some specific opportunities like DBA wants
to load data as soon as possible and/or the operation itself is easily *repeatable*.
So, before and after the change of wal_level, DBA needs to take a full backup to
prepare the unexpected crash.
But anyway, I'll fix and enrich the documents. Thanks.
Best,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-10-28 13:05 ` Laurenz Albe <[email protected]>
2020-10-28 20:32 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
0 siblings, 2 replies; 392+ messages in thread
From: Laurenz Albe @ 2020-10-28 13:05 UTC (permalink / raw)
To: [email protected] <[email protected]>; [email protected] <[email protected]>; 'Fujii Masao' <[email protected]>; Kyotaro Horiguchi <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
On Wed, 2020-10-28 at 09:55 +0000, [email protected] wrote:
> > > I wrote and attached the first patch to disable WAL logging.
> > > This patch passes the regression test of check-world already and is
> > > formatted by pgindent.
> >
> > Without reading the code, I have my doubts about that feature.
> > While it clearly will improve performance, it opens the door to data loss.
>
> Therefore, this feature must avoid that
> that kind of inconsistent server starts up again.
> This has been discussed in this thread already.
>
> > People will use it to speed up their data loads and then be unhappy if they
> > cannot use their backups to recover from a problem.
> > What happens if you try to do archive recovery across a time where wal_level
> > was "none"? Will the recovery process fail, as it should, or will you end up
> > with data corruption?
> > We already have a performance-related footgun in the shape of fsync = off.
> > Do we want to add another one?
>
> Further, in this thread, we discuss that
> this feature is intended to serve under
> some specific opportunities like DBA wants
> to load data as soon as possible and/or the operation itself is easily *repeatable*.
> So, before and after the change of wal_level, DBA needs to take a full backup to
> prepare the unexpected crash.
>
> But anyway, I'll fix and enrich the documents. Thanks.
I read through the thread and the patch now.
The only safety I see is that startup after a crash is prevented.
But what if someone sets wal_level=none, performs some data modifications,
sets wal_level=archive and after dome more processing decides to restore from
a backup that was taken before the cluster was set to wal_level=none?
Then they would end up with a corrupted database, right?
I think the least this patch needs is that starting with wal_level=none emits
a WAL record that will make recovery fail.
I am aware that this is intended for "specific opportunities", but we still
should make it as hard as possible for the user to cause harm. It may be that
MySQL, which inspired this feature, does not care about that, but I think we
should do better.
Another point that makes me worry is that this feature will unconditionally
break all replication, and there is not the least mention of that in the
documentation.
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
@ 2020-10-28 20:32 ` Laurenz Albe <[email protected]>
2020-10-29 00:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: Laurenz Albe @ 2020-10-28 20:32 UTC (permalink / raw)
To: [email protected] <[email protected]>; [email protected] <[email protected]>; 'Fujii Masao' <[email protected]>; Kyotaro Horiguchi <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
On Wed, 2020-10-28 at 14:05 +0100, I wrote:
> But what if someone sets wal_level=none, performs some data modifications,
> sets wal_level=archive and after dome more processing decides to restore from
> a backup that was taken before the cluster was set to wal_level=none?
> Then they would end up with a corrupted database, right?
>
> I think the least this patch needs is that starting with wal_level=none emits
> a WAL record that will make recovery fail.
I just realized that changing "wal_level" will cause a WAL record anyway.
Besides, the situation is not much different from changing to "wal_level = minimal".
So as long as PostgreSQL refuses to start after a crash, we should be good.
Sorry for the noise, and I am beginning to think that this is actually
a useful feature.
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 20:32 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
@ 2020-10-29 00:07 ` [email protected] <[email protected]>
2020-10-29 10:24 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-10-29 00:07 UTC (permalink / raw)
To: 'Laurenz Albe' <[email protected]>; [email protected] <[email protected]>; 'Fujii Masao' <[email protected]>; Kyotaro Horiguchi <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
Hello
> > But what if someone sets wal_level=none, performs some data
> > modifications, sets wal_level=archive and after dome more processing
> > decides to restore from a backup that was taken before the cluster was set
> to wal_level=none?
> > Then they would end up with a corrupted database, right?
> >
> > I think the least this patch needs is that starting with
> > wal_level=none emits a WAL record that will make recovery fail.
>
> I just realized that changing "wal_level" will cause a WAL record anyway.
> Besides, the situation is not much different from changing to "wal_level =
> minimal".
> So as long as PostgreSQL refuses to start after a crash, we should be good.
>
> Sorry for the noise, and I am beginning to think that this is actually a useful
> feature.
No problem at all.
Probably, for some developers, was the name "none" confusing ?
Also, thank you for your pointing out my lack of explanation
in the documents of the replication in the previous e-mail.
Best,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 20:32 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 00:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-10-29 10:24 ` Laurenz Albe <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Laurenz Albe @ 2020-10-29 10:24 UTC (permalink / raw)
To: [email protected] <[email protected]>; [email protected] <[email protected]>; 'Fujii Masao' <[email protected]>; Kyotaro Horiguchi <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
On Thu, 2020-10-29 at 00:07 +0000, [email protected] wrote:
> > Sorry for the noise, and I am beginning to think that this is actually a useful
> > feature.
>
> No problem at all.
> Probably, for some developers, was the name "none" confusing ?
No, I think that "none" is quite accurate.
The worry is that it makes it quite easy for people to end up with
a crashed database that cannot start - at the very least there should be
warnings in the documentation and postgresql.conf that are as dire as
for "fsync = off".
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
@ 2020-10-29 02:42 ` Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 2 replies; 392+ messages in thread
From: Fujii Masao @ 2020-10-29 02:42 UTC (permalink / raw)
To: Laurenz Albe <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
On 2020/10/28 22:05, Laurenz Albe wrote:
> On Wed, 2020-10-28 at 09:55 +0000, [email protected] wrote:
>>>> I wrote and attached the first patch to disable WAL logging.
>>>> This patch passes the regression test of check-world already and is
>>>> formatted by pgindent.
>>>
>>> Without reading the code, I have my doubts about that feature.
>>> While it clearly will improve performance, it opens the door to data loss.
>>
>> Therefore, this feature must avoid that
>> that kind of inconsistent server starts up again.
>> This has been discussed in this thread already.
>>
>>> People will use it to speed up their data loads and then be unhappy if they
>>> cannot use their backups to recover from a problem.
>>> What happens if you try to do archive recovery across a time where wal_level
>>> was "none"? Will the recovery process fail, as it should, or will you end up
>>> with data corruption?
>>> We already have a performance-related footgun in the shape of fsync = off.
>>> Do we want to add another one?
>>
>> Further, in this thread, we discuss that
>> this feature is intended to serve under
>> some specific opportunities like DBA wants
>> to load data as soon as possible and/or the operation itself is easily *repeatable*.
>> So, before and after the change of wal_level, DBA needs to take a full backup to
>> prepare the unexpected crash.
>>
>> But anyway, I'll fix and enrich the documents. Thanks.
>
> I read through the thread and the patch now.
>
> The only safety I see is that startup after a crash is prevented.
>
> But what if someone sets wal_level=none, performs some data modifications,
> sets wal_level=archive and after dome more processing decides to restore from
> a backup that was taken before the cluster was set to wal_level=none?
> Then they would end up with a corrupted database, right?
I think that the guard to prevent the server from starting up from
the corrupted database in that senario is necessary.
>
> I think the least this patch needs is that starting with wal_level=none emits
> a WAL record that will make recovery fail.
>
> I am aware that this is intended for "specific opportunities", but we still
> should make it as hard as possible for the user to cause harm. It may be that
> MySQL, which inspired this feature, does not care about that, but I think we
> should do better.
I'm still not sure if it's worth supporting this feature in core.
Because it can really really easily cause users to corrupt whole the database.
BTW, with the patch, I observed that PREPARE TRANSACTION and
COMMIT PREPARED caused assertion failure in my env, as I pointed upthread.
How does the patch handle other feature depending on the existence of WAL,
e.g., pg_logical_emit_message()?
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
@ 2020-10-29 10:21 ` Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: Laurenz Albe @ 2020-10-29 10:21 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
On Thu, 2020-10-29 at 11:42 +0900, Fujii Masao wrote:
> > But what if someone sets wal_level=none, performs some data modifications,
> > sets wal_level=archive and after dome more processing decides to restore from
> > a backup that was taken before the cluster was set to wal_level=none?
> > Then they would end up with a corrupted database, right?
>
> I think that the guard to prevent the server from starting up from
> the corrupted database in that senario is necessary.
That wouldn't apply, I think, because the backup from which you start
was taken with wal_level = replica, so the guard wouldn't alert.
But as I said in the other thread, changing wal_level emits a WAL
record, and I am sure that recovery will refuse to proceed if
wal_level < replica.
> I'm still not sure if it's worth supporting this feature in core.
> Because it can really really easily cause users to corrupt whole the database.
You mean, if they take no backup before setting wal_level = none
and then crash the database, so that they are stuck with an
unrecoverable database?
Yes, that feels somewhat too fast and loose...
It would at least require some fat warnings in the documentation
and in postgresql.conf.
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
@ 2020-10-29 20:00 ` Fujii Masao <[email protected]>
2020-10-30 04:32 ` Re: Disable WAL logging to speed up data loading Masahiko Sawada <[email protected]>
2020-10-30 12:28 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
0 siblings, 3 replies; 392+ messages in thread
From: Fujii Masao @ 2020-10-29 20:00 UTC (permalink / raw)
To: Laurenz Albe <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
On 2020/10/29 19:21, Laurenz Albe wrote:
> On Thu, 2020-10-29 at 11:42 +0900, Fujii Masao wrote:
>>> But what if someone sets wal_level=none, performs some data modifications,
>>> sets wal_level=archive and after dome more processing decides to restore from
>>> a backup that was taken before the cluster was set to wal_level=none?
>>> Then they would end up with a corrupted database, right?
>>
>> I think that the guard to prevent the server from starting up from
>> the corrupted database in that senario is necessary.
>
> That wouldn't apply, I think, because the backup from which you start
> was taken with wal_level = replica, so the guard wouldn't alert.
>
> But as I said in the other thread, changing wal_level emits a WAL
> record, and I am sure that recovery will refuse to proceed if
> wal_level < replica.
Yes. What I meant was such a safe guard needs to be implemented.
This may mean that if we want to recover the database from that backup,
we need to specify the recovery target so that the archive recovery stops
just before the WAL record indicating wal_level change.
>
>> I'm still not sure if it's worth supporting this feature in core.
>> Because it can really really easily cause users to corrupt whole the database.
>
> You mean, if they take no backup before setting wal_level = none
> and then crash the database, so that they are stuck with an
> unrecoverable database?
Yes. Also if the safe guard that we discussed the above is missing,
even when a backup is taken before wal_level=none, recovery from
the backup can make the database corrupted.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
@ 2020-10-30 04:32 ` Masahiko Sawada <[email protected]>
2020-11-02 00:27 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2 siblings, 1 reply; 392+ messages in thread
From: Masahiko Sawada @ 2020-10-30 04:32 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: Laurenz Albe <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
On Fri, 30 Oct 2020 at 05:00, Fujii Masao <[email protected]> wrote:
>
>
>
> On 2020/10/29 19:21, Laurenz Albe wrote:
> > On Thu, 2020-10-29 at 11:42 +0900, Fujii Masao wrote:
> >>> But what if someone sets wal_level=none, performs some data modifications,
> >>> sets wal_level=archive and after dome more processing decides to restore from
> >>> a backup that was taken before the cluster was set to wal_level=none?
> >>> Then they would end up with a corrupted database, right?
> >>
> >> I think that the guard to prevent the server from starting up from
> >> the corrupted database in that senario is necessary.
> >
> > That wouldn't apply, I think, because the backup from which you start
> > was taken with wal_level = replica, so the guard wouldn't alert.
> >
> > But as I said in the other thread, changing wal_level emits a WAL
> > record, and I am sure that recovery will refuse to proceed if
> > wal_level < replica.
>
> Yes. What I meant was such a safe guard needs to be implemented.
>
> This may mean that if we want to recover the database from that backup,
> we need to specify the recovery target so that the archive recovery stops
> just before the WAL record indicating wal_level change.
Yeah, it also means that setting wal_level to none makes the previous
backup no use even if the user has some generations of backup.
Does it make things simple if the usage of wal_level = 'none' is
limited to initial data loading for example? I mean we add a special
flag to initdb that sets wal_level to 'none' after initialization and
the user does initial data loading and set wal_level to >= minimal.
That is, we allow users to set from none to >= minimal but not for the
reverse. Since we prevent the database cluster from backup when
wal_level is none, the recovery never across wal_level = none. Not
sure this idea can address the case Osumi-san concerned though.
Regards,
--
Masahiko Sawada http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-30 04:32 ` Re: Disable WAL logging to speed up data loading Masahiko Sawada <[email protected]>
@ 2020-11-02 00:27 ` [email protected] <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: [email protected] @ 2020-11-02 00:27 UTC (permalink / raw)
To: 'Masahiko Sawada' <[email protected]>; Fujii Masao <[email protected]>; +Cc: Laurenz Albe <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Hello
On Friday, October 30, 2020 1:32 PM Masahiko Sawada wrote:
> > On 2020/10/29 19:21, Laurenz Albe wrote:
> > > On Thu, 2020-10-29 at 11:42 +0900, Fujii Masao wrote:
> > >>> But what if someone sets wal_level=none, performs some data
> > >>> modifications, sets wal_level=archive and after dome more
> > >>> processing decides to restore from a backup that was taken before
> the cluster was set to wal_level=none?
> > >>> Then they would end up with a corrupted database, right?
> > >>
> > >> I think that the guard to prevent the server from starting up from
> > >> the corrupted database in that senario is necessary.
> > >
> > > That wouldn't apply, I think, because the backup from which you
> > > start was taken with wal_level = replica, so the guard wouldn't alert.
> > >
> > > But as I said in the other thread, changing wal_level emits a WAL
> > > record, and I am sure that recovery will refuse to proceed if
> > > wal_level < replica.
> >
> > Yes. What I meant was such a safe guard needs to be implemented.
> >
> > This may mean that if we want to recover the database from that
> > backup, we need to specify the recovery target so that the archive
> > recovery stops just before the WAL record indicating wal_level change.
>
> Yeah, it also means that setting wal_level to none makes the previous backup
> no use even if the user has some generations of backup.
>
> Does it make things simple if the usage of wal_level = 'none' is limited to
> initial data loading for example? I mean we add a special flag to initdb that
> sets wal_level to 'none' after initialization and the user does initial data
> loading and set wal_level to >= minimal.
> That is, we allow users to set from none to >= minimal but not for the reverse.
> Since we prevent the database cluster from backup when wal_level is none,
> the recovery never across wal_level = none. Not sure this idea can address
> the case Osumi-san concerned though.
Thanks you so much for the discussion.
Hmm, this was a good idea to implement
some kind of valve to prevent backflow of wal_levels.
But, ideally I'd like to allow users to switch wal_levels from/to 'none',
in order to let them operate bulk load in a faster way by this feature
even if that operation isn't for the initial data loading.
Regards,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
@ 2020-10-30 12:28 ` Laurenz Albe <[email protected]>
2 siblings, 0 replies; 392+ messages in thread
From: Laurenz Albe @ 2020-10-30 12:28 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected]; Kyotaro Horiguchi <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
On Fri, 2020-10-30 at 05:00 +0900, Fujii Masao wrote:
> > But as I said in the other thread, changing wal_level emits a WAL
> > record, and I am sure that recovery will refuse to proceed if
> > wal_level < replica.
>
> Yes. What I meant was such a safe guard needs to be implemented.
That should be easy; just modify this code:
static void
CheckRequiredParameterValues(void)
{
/*
* For archive recovery, the WAL must be generated with at least 'replica'
* wal_level.
*/
if (ArchiveRecoveryRequested &&
ControlFile->wal_level == WAL_LEVEL_MINIMAL)
{
ereport(WARNING,
(errmsg("WAL was generated with wal_level=minimal, data may be missing"),
errhint("This happens
if you temporarily set wal_level=minimal without taking a new base backup.")));
}
so that it tests
if (ArchiveRecoveryRequested && ControlFile->wal_level <= WAL_LEVEL_MINIMAL)
and we should be safe.
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
@ 2020-11-02 15:28 ` Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-17 01:45 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2 siblings, 2 replies; 392+ messages in thread
From: Robert Haas @ 2020-11-02 15:28 UTC (permalink / raw)
To: Fujii Masao <[email protected]>; +Cc: Laurenz Albe <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
On Thu, Oct 29, 2020 at 4:00 PM Fujii Masao <[email protected]> wrote:
> Yes. What I meant was such a safe guard needs to be implemented.
>
> This may mean that if we want to recover the database from that backup,
> we need to specify the recovery target so that the archive recovery stops
> just before the WAL record indicating wal_level change.
Yeah, I think we need these kinds of safeguards, for sure.
I'm also concerned about the way that this proposed feature interacts
with incremental backup capabilities that already exist in tools like
pgBackRest, EDB's BART, pg_probackup, and future things we might want
to introduce into core, along the lines of what I have previously
proposed. Now, I think pgBackRest uses only timestamps and checksums,
so it probably doesn't care, but some of the other solutions rely on
WAL-scanning to gather a list of changed blocks. I guess there's no
reason that they can't notice the wal_level being changed and do the
right thing; they should probably have that kind of capability
already. Still, it strikes me that it might be useful if we had a
stronger mechanism.
I'm not exactly sure what that would look like, but suppose we had a
feature where every time wal_level drops below replica, a counter gets
incremented by 1, and that counter is saved in the control file. Or
maybe when wal_level drops below minimal to none. Or maybe there are
two counters. Anyway, the idea is that if you have a snapshot of the
cluster at one time and a snapshot at another time, you can see
whether anything scary has happened in the middle without needing all
of the WAL in between.
Maybe this is off-topic for this thread or not really needed, but I'm
not sure. I don't think wal_level=none is a bad idea intrinsically,
but I think it would be easy to implement it poorly and end up harming
a lot of users. I have no problem with giving people a way to do
dangerous things, but we should do our best to let people know how
much danger they've incurred.
By the way, another problem here is that some AMs - e.g. GiST, IIRC -
use LSNs to figure out whether a block has changed. For temporary and
unlogged tables, we use "fake" LSNs that are generated using a
counter, but that approach only works because such relations are never
really WAL-logged. Mixing fake LSNs and real LSNs will break stuff,
and not bumping the LSN when the page changes probably will, too.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
@ 2020-11-02 15:35 ` Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: Magnus Hagander @ 2020-11-02 15:35 UTC (permalink / raw)
To: Robert Haas <[email protected]>; +Cc: Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
On Mon, Nov 2, 2020 at 4:28 PM Robert Haas <[email protected]> wrote:
>
> On Thu, Oct 29, 2020 at 4:00 PM Fujii Masao <[email protected]> wrote:
> > Yes. What I meant was such a safe guard needs to be implemented.
> >
> > This may mean that if we want to recover the database from that backup,
> > we need to specify the recovery target so that the archive recovery stops
> > just before the WAL record indicating wal_level change.
>
> Yeah, I think we need these kinds of safeguards, for sure.
>
> I'm also concerned about the way that this proposed feature interacts
> with incremental backup capabilities that already exist in tools like
> pgBackRest, EDB's BART, pg_probackup, and future things we might want
> to introduce into core, along the lines of what I have previously
> proposed. Now, I think pgBackRest uses only timestamps and checksums,
> so it probably doesn't care, but some of the other solutions rely on
> WAL-scanning to gather a list of changed blocks. I guess there's no
> reason that they can't notice the wal_level being changed and do the
> right thing; they should probably have that kind of capability
> already. Still, it strikes me that it might be useful if we had a
> stronger mechanism.
>
> I'm not exactly sure what that would look like, but suppose we had a
> feature where every time wal_level drops below replica, a counter gets
> incremented by 1, and that counter is saved in the control file. Or
> maybe when wal_level drops below minimal to none. Or maybe there are
> two counters. Anyway, the idea is that if you have a snapshot of the
> cluster at one time and a snapshot at another time, you can see
> whether anything scary has happened in the middle without needing all
> of the WAL in between.
>
> Maybe this is off-topic for this thread or not really needed, but I'm
> not sure. I don't think wal_level=none is a bad idea intrinsically,
> but I think it would be easy to implement it poorly and end up harming
> a lot of users. I have no problem with giving people a way to do
> dangerous things, but we should do our best to let people know how
> much danger they've incurred.
I definitely think this is something that should be thought out and
included in a patch like this, so it's definitely on-topic for this
thread.
Having the ability to turn things off can certainly be very useful.
Having the risk of having done so without realizing the damage caused
is a *big* foot-gun, and we need to do our best to protect against it.
This is not entirely unlike the idea that we've discussed before of
having basically a "tainted" flag in pg_control if the system has ever
been started up in say fsync=off, just to make sure that we have a
record of it. This wouldn't be the same flag of course, but it's a
similar problem, where even temporarily starting the cluster up with a
certain set of flags can do permanent damage which is not necessarily
fixed by changing it back and restarting.
This would also be something that should be exposed as monitoring
points (which it could be if it's in pg_control). That is, I can
imagine a *lot* of installations that would definitely want an alert
to fire if the cluster has ever been started up in a wal_level=none or
wal_level=minimal, at least up until the point where somebody has run
a new full backup.
--
Magnus Hagander
Me: https://www.hagander.net/
Work: https://www.redpill-linpro.com/
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
@ 2020-11-02 18:01 ` Stephen Frost <[email protected]>
2020-11-09 06:30 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 02:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
0 siblings, 2 replies; 392+ messages in thread
From: Stephen Frost @ 2020-11-02 18:01 UTC (permalink / raw)
To: Magnus Hagander <[email protected]>; +Cc: Robert Haas <[email protected]>; Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Greetings,
* Magnus Hagander ([email protected]) wrote:
> On Mon, Nov 2, 2020 at 4:28 PM Robert Haas <[email protected]> wrote:
> >
> > On Thu, Oct 29, 2020 at 4:00 PM Fujii Masao <[email protected]> wrote:
> > > Yes. What I meant was such a safe guard needs to be implemented.
> > >
> > > This may mean that if we want to recover the database from that backup,
> > > we need to specify the recovery target so that the archive recovery stops
> > > just before the WAL record indicating wal_level change.
> >
> > Yeah, I think we need these kinds of safeguards, for sure.
> >
> > I'm also concerned about the way that this proposed feature interacts
> > with incremental backup capabilities that already exist in tools like
> > pgBackRest, EDB's BART, pg_probackup, and future things we might want
> > to introduce into core, along the lines of what I have previously
> > proposed. Now, I think pgBackRest uses only timestamps and checksums,
> > so it probably doesn't care, but some of the other solutions rely on
> > WAL-scanning to gather a list of changed blocks. I guess there's no
> > reason that they can't notice the wal_level being changed and do the
> > right thing; they should probably have that kind of capability
> > already. Still, it strikes me that it might be useful if we had a
> > stronger mechanism.
Checking the WAL level certainly seems critical to anything that's
reading the WAL. We certainly do this already when running as a
replica:
ereport(WARNING,
(errmsg("WAL was generated with wal_level=minimal, data may be missing"),
errhint("This happens if you temporarily set wal_level=minimal without taking a new base backup.")));
There's definitely a question about if a WARNING there is really
sufficient or not, considering that you could end up with 'logged'
tables on the replica that are missing data, but I'm not sure that
inventing a new, independent, mechanism for checking WAL level changes
makes sense.
While pgbackrest backups of a primary wouldn't be impacted, it does
support backing up from a replica (as do other backup systems, of
course) and if data that's supposed to be on the replica isn't there
because someone restarted PG with wal_level=minimal and then flipped it
back to replica and got the replica to move past that part of the WAL by
turning off hot standby, replaying, and then turning it back on, then
the backup is going to also be missing that data.
Perhaps that's where we need to have a stronger mechanism though- that
is, if we hit the above WARNING, ever, set a flag somewhere that tools
can check and which we could also check and throw further warnings
about. In other words, every time this replica is started, we could
check for this flag and throw the same warning above about how data may
be missing, and we could have pg_basebackup flat out refuse to back up
from a replica where this flag has been set (maybe with some kind of
override mechanism... maybe not). After all, that's where the real
issue here is, isn't it?
> > I'm not exactly sure what that would look like, but suppose we had a
> > feature where every time wal_level drops below replica, a counter gets
> > incremented by 1, and that counter is saved in the control file. Or
> > maybe when wal_level drops below minimal to none. Or maybe there are
> > two counters. Anyway, the idea is that if you have a snapshot of the
> > cluster at one time and a snapshot at another time, you can see
> > whether anything scary has happened in the middle without needing all
> > of the WAL in between.
> >
> > Maybe this is off-topic for this thread or not really needed, but I'm
> > not sure. I don't think wal_level=none is a bad idea intrinsically,
> > but I think it would be easy to implement it poorly and end up harming
> > a lot of users. I have no problem with giving people a way to do
> > dangerous things, but we should do our best to let people know how
> > much danger they've incurred.
I'm not sure that wal_level=none is really the right way to address this
use-case. We already have unlogged tables and that's pretty clean and
meets the "we want to load data fast without having to pay for WAL" use
case. The argument here seems to be that to take advantage of unlogged
tables requires the tools using PG to know how to issue a 'CREATE
UNLOGGED TABLE' command instead of a 'CREATE TABLE' command. That
doesn't seem like a huge leap, but we could make it easier by just
adding a 'table_log_default' or such GUC that could be set on the data
loading role to have all tables created by it be unlogged.
Looking back at the thread, it seems that perhaps the one other area
where this isn't ideal is when the user ultimately wants the data to be
*considered* logged even when it wasn't (ie: change from wal_level none,
or minimal, back to replica). On a quick look, it seems that we're
missing a trick there for UNLOGGED -> LOGGED changes since, while I
don't think we'll WAL the table during that if wal_level is set to
minimal, I do think we'll still end up pointlessly making a copy of all
of the data when we don't really need to..? Fixing that would be useful
in its own right though.
> I definitely think this is something that should be thought out and
> included in a patch like this, so it's definitely on-topic for this
> thread.
Considering it's an existing problem we have, I'm not entirely convinced
that it's on this patch to fix it beyond making sure to document the
impact. That said, mucking with WAL level seems like a really big
hammer and it'd be nice if we could support this use case with more
granularity, as I try to outline above.
> Having the ability to turn things off can certainly be very useful.
> Having the risk of having done so without realizing the damage caused
> is a *big* foot-gun, and we need to do our best to protect against it.
I don't know that we really do enough in this regard, today, and maybe
that's something we should discuss changing, but that's not really a new
concern that this patch is introducing.
> This is not entirely unlike the idea that we've discussed before of
> having basically a "tainted" flag in pg_control if the system has ever
> been started up in say fsync=off, just to make sure that we have a
> record of it. This wouldn't be the same flag of course, but it's a
> similar problem, where even temporarily starting the cluster up with a
> certain set of flags can do permanent damage which is not necessarily
> fixed by changing it back and restarting.
While I think I understand the concern, I'm not sure that it entirely
applies to the fsync=off case unless the system isn't cleanly shut down
too, something that is usually caught and detected through other means.
Having the WAL level be lowered to minimal is something that can cause a
replica to end up getting corrupted even without an unclean restart or
similar happening.
> This would also be something that should be exposed as monitoring
> points (which it could be if it's in pg_control). That is, I can
> imagine a *lot* of installations that would definitely want an alert
> to fire if the cluster has ever been started up in a wal_level=none or
> wal_level=minimal, at least up until the point where somebody has run
> a new full backup.
I agree with the general idea that it'd be good for anything we do here
to be made available for monitoring tools to be able to see.
Thanks,
Stephen
Attachments:
[application/pgp-signature] signature.asc (819B, ../../[email protected]/2-signature.asc)
download
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
@ 2020-11-09 06:30 ` [email protected] <[email protected]>
2020-11-09 15:18 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-11-09 06:30 UTC (permalink / raw)
To: 'Stephen Frost' <[email protected]>; Magnus Hagander <[email protected]>; +Cc: Robert Haas <[email protected]>; Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Hello, Stephen
On Tuesday, Nov 3, 2020 3:02 AM Stephen Frost <[email protected]> wrote:
> * Magnus Hagander ([email protected]) wrote:
> > On Mon, Nov 2, 2020 at 4:28 PM Robert Haas <[email protected]>
> wrote:
> > > On Thu, Oct 29, 2020 at 4:00 PM Fujii Masao
> <[email protected]> wrote:
> > > > Yes. What I meant was such a safe guard needs to be implemented.
> > > >
> > > > This may mean that if we want to recover the database from that
> > > > backup, we need to specify the recovery target so that the archive
> > > > recovery stops just before the WAL record indicating wal_level change.
> > >
> > > Yeah, I think we need these kinds of safeguards, for sure.
> > >
> > > I'm also concerned about the way that this proposed feature
> > > interacts with incremental backup capabilities that already exist in
> > > tools like pgBackRest, EDB's BART, pg_probackup, and future things
> > > we might want to introduce into core, along the lines of what I have
> > > previously proposed. Now, I think pgBackRest uses only timestamps
> > > and checksums, so it probably doesn't care, but some of the other
> > > solutions rely on WAL-scanning to gather a list of changed blocks. I
> > > guess there's no reason that they can't notice the wal_level being
> > > changed and do the right thing; they should probably have that kind
> > > of capability already. Still, it strikes me that it might be useful
> > > if we had a stronger mechanism.
>
> Checking the WAL level certainly seems critical to anything that's reading the
> WAL. We certainly do this already when running as a
> replica:
>
> ereport(WARNING,
> (errmsg("WAL was generated with wal_level=minimal, data may be
> missing"),
> errhint("This happens if you temporarily set wal_level=minimal
> without taking a new base backup.")));
>
> There's definitely a question about if a WARNING there is really sufficient or
> not, considering that you could end up with 'logged'
> tables on the replica that are missing data, but I'm not sure that inventing a
> new, independent, mechanism for checking WAL level changes makes sense.
>
> While pgbackrest backups of a primary wouldn't be impacted, it does support
> backing up from a replica (as do other backup systems, of
> course) and if data that's supposed to be on the replica isn't there because
> someone restarted PG with wal_level=minimal and then flipped it back to
> replica and got the replica to move past that part of the WAL by turning off hot
> standby, replaying, and then turning it back on, then the backup is going to
> also be missing that data.
>
> Perhaps that's where we need to have a stronger mechanism though- that is,
> if we hit the above WARNING, ever, set a flag somewhere that tools can check
> and which we could also check and throw further warnings about. In other
> words, every time this replica is started, we could check for this flag and
> throw the same warning above about how data may be missing, and we could
> have pg_basebackup flat out refuse to back up from a replica where this flag
> has been set (maybe with some kind of override mechanism... maybe not).
> After all, that's where the real issue here is, isn't it?
>
> > > I'm not exactly sure what that would look like, but suppose we had a
> > > feature where every time wal_level drops below replica, a counter
> > > gets incremented by 1, and that counter is saved in the control
> > > file. Or maybe when wal_level drops below minimal to none. Or maybe
> > > there are two counters. Anyway, the idea is that if you have a
> > > snapshot of the cluster at one time and a snapshot at another time,
> > > you can see whether anything scary has happened in the middle
> > > without needing all of the WAL in between.
> > >
> > > Maybe this is off-topic for this thread or not really needed, but
> > > I'm not sure. I don't think wal_level=none is a bad idea
> > > intrinsically, but I think it would be easy to implement it poorly
> > > and end up harming a lot of users. I have no problem with giving
> > > people a way to do dangerous things, but we should do our best to
> > > let people know how much danger they've incurred.
>
> I'm not sure that wal_level=none is really the right way to address this
> use-case. We already have unlogged tables and that's pretty clean and
> meets the "we want to load data fast without having to pay for WAL" use case.
> The argument here seems to be that to take advantage of unlogged tables
> requires the tools using PG to know how to issue a 'CREATE UNLOGGED
> TABLE' command instead of a 'CREATE TABLE' command. That doesn't
> seem like a huge leap, but we could make it easier by just adding a
> 'table_log_default' or such GUC that could be set on the data loading role to
> have all tables created by it be unlogged.
I'm afraid to say that in the case to setup all tables as unlogged,
the user are forced to be under tension to
back up *all* commands from application, in preparation for unexpected crash.
This is because whenever the server crashes,
the unlogged tables are truncated and the DBA needs to
input the processings after the last backup again without exception.
I didn't think that this was easy and satisfied the user.
In addition, as long as the tables are unlogged, the user cannot be released from
this condition or (requirement ?) to back up all commands or
to guarantee that all commands are repeatable for the DBA.
When I consider the use case is the system of data warehouse
as described upthread, the size of each table can be large.
Thus, changing the status from unlogged to logged (recoverable)
takes much time under the current circumstances, which was discussed before.
By having the limited window of time,
during wal_level=none, I'd like to make wal_level=none work to
localize and minimize the burden to guarantee all commands are
repeatable. To achieve this, after switching wal_level from none to higher ones,
the patch must ensure crash recovery, though.
Sorry that my current patch doesn't complete this aspect fully at present
but, may I have your opinion about this ?
Best,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 06:30 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-09 15:18 ` Stephen Frost <[email protected]>
2020-11-09 17:05 ` Re: Disable WAL logging to speed up data loading David G. Johnston <[email protected]>
2020-11-10 00:59 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
0 siblings, 2 replies; 392+ messages in thread
From: Stephen Frost @ 2020-11-09 15:18 UTC (permalink / raw)
To: [email protected] <[email protected]>; +Cc: Magnus Hagander <[email protected]>; Robert Haas <[email protected]>; Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Greetings,
* [email protected] ([email protected]) wrote:
> On Tuesday, Nov 3, 2020 3:02 AM Stephen Frost <[email protected]> wrote:
> > I'm not sure that wal_level=none is really the right way to address this
> > use-case. We already have unlogged tables and that's pretty clean and
> > meets the "we want to load data fast without having to pay for WAL" use case.
> > The argument here seems to be that to take advantage of unlogged tables
> > requires the tools using PG to know how to issue a 'CREATE UNLOGGED
> > TABLE' command instead of a 'CREATE TABLE' command. That doesn't
> > seem like a huge leap, but we could make it easier by just adding a
> > 'table_log_default' or such GUC that could be set on the data loading role to
> > have all tables created by it be unlogged.
> I'm afraid to say that in the case to setup all tables as unlogged,
> the user are forced to be under tension to
> back up *all* commands from application, in preparation for unexpected crash.
> This is because whenever the server crashes,
> the unlogged tables are truncated and the DBA needs to
> input the processings after the last backup again without exception.
> I didn't think that this was easy and satisfied the user.
You'll need to explain how this is different from the proposed
'wal_level = none' option, since it sounded like that would be exactly
the same case..?
> In addition, as long as the tables are unlogged, the user cannot be released from
> this condition or (requirement ?) to back up all commands or
> to guarantee that all commands are repeatable for the DBA.
They can change the table to be logged though, if they wish to.
> When I consider the use case is the system of data warehouse
> as described upthread, the size of each table can be large.
> Thus, changing the status from unlogged to logged (recoverable)
> takes much time under the current circumstances, which was discussed before.
Ok- so the issue is that, today, we dump all of the table into the WAL
when we go from unlogged to logged, but as I outlined previously,
perhaps that's because we're missing a trick there when
wal_level=minimal. If wal_level=minimal, then it would seem like we
could lock the table, then sync it and then mark is as logged, which is
more-or-less what you're asking to have be effectively done with the
proposed wal_level=none, but this would be an optimization for all
existing users of wal_level=minimal who have unlogged tables that they
want to change to logged, and this works on a per-table basis instead,
which seems like a better approach than a cluster-wide setting.
> By having the limited window of time,
> during wal_level=none, I'd like to make wal_level=none work to
> localize and minimize the burden to guarantee all commands are
> repeatable. To achieve this, after switching wal_level from none to higher ones,
> the patch must ensure crash recovery, though.
Perhaps a helper command could be added to ALTER TABLE ALL IN TABLESPACE
to marked a bunch of unlogged tables over to being logged would be good
to add too.
> Sorry that my current patch doesn't complete this aspect fully at present
> but, may I have your opinion about this ?
Presently, my feeling is that we could address this use-case without
having to introduce a new cluster-wide WAL level, and that's the
direction I'd want to see this going. Perhaps I'm missing something
about why the approach I've set forth above wouldn't work, and
wal_level=none would, but I've not seen it yet.
Thanks,
Stephen
Attachments:
[application/pgp-signature] signature.asc (819B, ../../[email protected]/2-signature.asc)
download
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 06:30 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-09 15:18 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
@ 2020-11-09 17:05 ` David G. Johnston <[email protected]>
2020-11-09 17:36 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-17 02:49 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 2 replies; 392+ messages in thread
From: David G. Johnston @ 2020-11-09 17:05 UTC (permalink / raw)
To: Stephen Frost <[email protected]>; +Cc: [email protected] <[email protected]>; Magnus Hagander <[email protected]>; Robert Haas <[email protected]>; Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
On Mon, Nov 9, 2020 at 8:18 AM Stephen Frost <[email protected]> wrote:
> Presently, my feeling is that we could address this use-case without
>
having to introduce a new cluster-wide WAL level, and that's the
> direction I'd want to see this going. Perhaps I'm missing something
> about why the approach I've set forth above wouldn't work, and
> wal_level=none would, but I've not seen it yet.
>
>
+1
We are trying to address a performance optimization for an insert-only
scenario on a limited set of tables by placing the entire cluster in a
dangerous state. The "copy table unlogged" solution is definitely closer
to what we want - this is
demonstrably worse.
For this case the fundamental feature that would seem to be required is an
ability for a transaction commit to return only after the system has
ensured that all of the new pages added to the relation during the scope of
the transaction have made it to disk. Something like:
BEGIN UNLOGGED TRANSACTION FOR table1, table2;
-- locking probably allows reads, definitely disallows concurrent writes,
to the named tables
-- Disallow updates and deletes, do not use dead tuple space, for the
tables named. Should be able to do normal stuff for other tables?
-- Always create new pages
COPY TO table1;
COPY TO table2;
COMMIT; -- wait here until data files for table1 and table2 are completely
written and the transaction alive flag is committed to the WAL.
I suppose the above could be written "BEGIN UNLOGGED TRANSACTION FOR ALL
TABLES" and you'd get the initial database population optimization
capability.
If the commit doesn't complete all of the newly created pages are junk.
Otherwise, you have a crash-recoverable state for those tables as regards
those specific pages.
Conceptually, we need an ability to perform a partial CHECKPOINT that names
specific tables, and make sure the crash-recovery works for those tables
while figuring out what amount of effort to expend on informing the dba and
alerting/preventing features that require wal from using those tables.
David J.
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 06:30 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-09 15:18 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 17:05 ` Re: Disable WAL logging to speed up data loading David G. Johnston <[email protected]>
@ 2020-11-09 17:36 ` Stephen Frost <[email protected]>
2020-11-09 18:20 ` Re: Disable WAL logging to speed up data loading David G. Johnston <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: Stephen Frost @ 2020-11-09 17:36 UTC (permalink / raw)
To: David G. Johnston <[email protected]>; +Cc: [email protected] <[email protected]>; Magnus Hagander <[email protected]>; Robert Haas <[email protected]>; Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Greetings,
* David G. Johnston ([email protected]) wrote:
> On Mon, Nov 9, 2020 at 8:18 AM Stephen Frost <[email protected]> wrote:
> > Presently, my feeling is that we could address this use-case without
> > having to introduce a new cluster-wide WAL level, and that's the
> > direction I'd want to see this going. Perhaps I'm missing something
> > about why the approach I've set forth above wouldn't work, and
> > wal_level=none would, but I've not seen it yet.
>
> +1
>
> We are trying to address a performance optimization for an insert-only
> scenario on a limited set of tables by placing the entire cluster in a
> dangerous state. The "copy table unlogged" solution is definitely closer
> to what we want - this is
> demonstrably worse.
Yeah, agreed.
> For this case the fundamental feature that would seem to be required is an
> ability for a transaction commit to return only after the system has
> ensured that all of the new pages added to the relation during the scope of
> the transaction have made it to disk. Something like:
>
> BEGIN UNLOGGED TRANSACTION FOR table1, table2;
> -- locking probably allows reads, definitely disallows concurrent writes,
> to the named tables
> -- Disallow updates and deletes, do not use dead tuple space, for the
> tables named. Should be able to do normal stuff for other tables?
> -- Always create new pages
> COPY TO table1;
> COPY TO table2;
> COMMIT; -- wait here until data files for table1 and table2 are completely
> written and the transaction alive flag is committed to the WAL.
That's certainly an interesting idea, but seems like a much larger step
than just making some improvements to how UNLOGGED tables work today,
and then perhaps some helper options to make it easier to create
UNLOGGED tables and change them from unlogged to logged when the
wal_level is set to 'minimal'.
Also- I don't think this would end up working for normally logged
relations at a wal_level higher than 'minimal', since if we don't
log those pages then they won't get to replicas.
> I suppose the above could be written "BEGIN UNLOGGED TRANSACTION FOR ALL
> TABLES" and you'd get the initial database population optimization
> capability.
Or just 'BEGIN UNLOGGED TRANSACTION'.. I wonder if we'd have to run
around and lock all tables as you're suggesting above or if we could
just lock them as they get used..
> If the commit doesn't complete all of the newly created pages are junk.
> Otherwise, you have a crash-recoverable state for those tables as regards
> those specific pages.
How would we track that and know which pages are junk?
> Conceptually, we need an ability to perform a partial CHECKPOINT that names
> specific tables, and make sure the crash-recovery works for those tables
> while figuring out what amount of effort to expend on informing the dba and
> alerting/preventing features that require wal from using those tables.
Yeah, seems pretty complicated.
Did you see an issue with the basic idea I proposed earlier, whereby an
unlogged table could become 'logged', while we are at wal_level=minimal,
by essentially checkpointing it (locking it, forcing out any buffers we
have associated with it, and then fsync'ing it- not sure how much of
that is already done in the unlogged->logged process but I would guess
most of it) while not actually writing it into the WAL?
Thanks,
Stephen
Attachments:
[application/pgp-signature] signature.asc (819B, ../../[email protected]/2-signature.asc)
download
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 06:30 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-09 15:18 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 17:05 ` Re: Disable WAL logging to speed up data loading David G. Johnston <[email protected]>
2020-11-09 17:36 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
@ 2020-11-09 18:20 ` David G. Johnston <[email protected]>
2020-11-09 19:26 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: David G. Johnston @ 2020-11-09 18:20 UTC (permalink / raw)
To: Stephen Frost <[email protected]>; +Cc: [email protected] <[email protected]>; Magnus Hagander <[email protected]>; Robert Haas <[email protected]>; Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
On Mon, Nov 9, 2020 at 10:36 AM Stephen Frost <[email protected]> wrote:
> * David G. Johnston ([email protected]) wrote:
>
> > If the commit doesn't complete all of the newly created pages are junk.
> > Otherwise, you have a crash-recoverable state for those tables as regards
> > those specific pages.
>
> How would we track that and know which pages are junk?
>
Every one of those pages would have a single dead transaction id contained
within it. If there is bookkeeping that needs to happen that could be wal
logged - the goal here being not to avoid all wal but to avoid data wal. I
don't know enough about the internals here to be more specific.
> > Conceptually, we need an ability to perform a partial CHECKPOINT that
> names
> > specific tables, and make sure the crash-recovery works for those tables
> > while figuring out what amount of effort to expend on informing the dba
> and
> > alerting/preventing features that require wal from using those tables.
>
> Yeah, seems pretty complicated.
>
> Did you see an issue with the basic idea I proposed earlier, whereby an
> unlogged table could become 'logged', while we are at wal_level=minimal,
> by essentially checkpointing it (locking it, forcing out any buffers we
> have associated with it, and then fsync'ing it- not sure how much of
> that is already done in the unlogged->logged process but I would guess
> most of it) while not actually writing it into the WAL?
>
That is basically half of what is described above - the part at commit when
the relation is persisted to disk. What your earlier description seems to
be missing is the part about temporarily making a logged relation
unlogged. I envision that as being part of a transaction as opposed to a
permanent attribute of the table. I envision a storage parameter that
allows individual relations to be considered as having wal_level='minimal'
even if the system as a whole has, e.g., wal_level='replication'. Only
those could be forced into this temporarily unlogged mode.
One part I hadn't given thought to is indexes and how those would interact
with this plan. Mostly due to lack of internals knowledge.
David J.
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 06:30 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-09 15:18 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 17:05 ` Re: Disable WAL logging to speed up data loading David G. Johnston <[email protected]>
2020-11-09 17:36 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 18:20 ` Re: Disable WAL logging to speed up data loading David G. Johnston <[email protected]>
@ 2020-11-09 19:26 ` Stephen Frost <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Stephen Frost @ 2020-11-09 19:26 UTC (permalink / raw)
To: David G. Johnston <[email protected]>; +Cc: [email protected] <[email protected]>; Magnus Hagander <[email protected]>; Robert Haas <[email protected]>; Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Greetings,
* David G. Johnston ([email protected]) wrote:
> On Mon, Nov 9, 2020 at 10:36 AM Stephen Frost <[email protected]> wrote:
> > * David G. Johnston ([email protected]) wrote:
> > > If the commit doesn't complete all of the newly created pages are junk.
> > > Otherwise, you have a crash-recoverable state for those tables as regards
> > > those specific pages.
> >
> > How would we track that and know which pages are junk?
>
> Every one of those pages would have a single dead transaction id contained
> within it. If there is bookkeeping that needs to happen that could be wal
> logged - the goal here being not to avoid all wal but to avoid data wal. I
> don't know enough about the internals here to be more specific.
Yeah, not sure how well that would end up working.. Maybe there's a way
to get there, but definitely a fair bit of complicated work.
> > > Conceptually, we need an ability to perform a partial CHECKPOINT that
> > names
> > > specific tables, and make sure the crash-recovery works for those tables
> > > while figuring out what amount of effort to expend on informing the dba
> > and
> > > alerting/preventing features that require wal from using those tables.
> >
> > Yeah, seems pretty complicated.
> >
> > Did you see an issue with the basic idea I proposed earlier, whereby an
> > unlogged table could become 'logged', while we are at wal_level=minimal,
> > by essentially checkpointing it (locking it, forcing out any buffers we
> > have associated with it, and then fsync'ing it- not sure how much of
> > that is already done in the unlogged->logged process but I would guess
> > most of it) while not actually writing it into the WAL?
>
> That is basically half of what is described above - the part at commit when
> the relation is persisted to disk.
Right, think I agree with you there.
> What your earlier description seems to
> be missing is the part about temporarily making a logged relation
> unlogged.
While I get that there may be use-cases for that, it seems that the
use-case being described here doesn't require it- there just needs to be
a way to take the unlogged table and make it into a 'logged' table
without having to actually write it all into the WAL when wal_level is
minimal.
There may be another option to addressing the use-case as you're looking
at it though- by using partitioning. That is, there's a partitioned
table which has logged tables in it, a new unlogged table is created and
added to the partitioned table, it's then loaded, and then it's
converted to being logged (or maybe it's loaded first and then added to
the partitioned table, either way). This would also have the advantage
that you'd be able to continue making changes to the partitioned table
as you normally do, in general.
> I envision that as being part of a transaction as opposed to a
> permanent attribute of the table. I envision a storage parameter that
> allows individual relations to be considered as having wal_level='minimal'
> even if the system as a whole has, e.g., wal_level='replication'. Only
> those could be forced into this temporarily unlogged mode.
I mean ... we have a way of saying that individual relations have a
lower WAL level than others- they're UNLOGGED. I'm still seeing this as
an opportunity to build on that and improve that, rather than invent
something new.
Thanks,
Stephen
Attachments:
[application/pgp-signature] signature.asc (819B, ../../[email protected]/2-signature.asc)
download
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 06:30 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-09 15:18 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 17:05 ` Re: Disable WAL logging to speed up data loading David G. Johnston <[email protected]>
@ 2020-11-17 02:49 ` [email protected] <[email protected]>
1 sibling, 0 replies; 392+ messages in thread
From: [email protected] @ 2020-11-17 02:49 UTC (permalink / raw)
To: 'David G. Johnston' <[email protected]>; +Cc: Stephen Frost <[email protected]>; [email protected] <[email protected]>; Magnus Hagander <[email protected]>; Robert Haas <[email protected]>; Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
# It'd be helpful if you could send mails in text format, not HTML.
From: David G. Johnston <[email protected]>
> For this case the fundamental feature that would seem to be required is an ability for a transaction commit to return only after the system has ensured that all of the new pages added to the relation during the scope of the transaction have made it to disk. Something like:
>
> BEGIN UNLOGGED TRANSACTION FOR table1, table2;
> -- locking probably allows reads, definitely disallows concurrent writes, to the named tables
> -- Disallow updates and deletes, do not use dead tuple space, for the tables named. Should be able to do normal stuff for other tables?
> -- Always create new pages
> COPY TO table1;
> COPY TO table2;
> COMMIT; -- wait here until data files for table1 and table2 are completely written and the transaction alive flag is committed to the WAL.
>
> I suppose the above could be written "BEGIN UNLOGGED TRANSACTION FOR ALL TABLES" and you'd get the initial database population optimization capability.
>
> If the commit doesn't complete all of the newly created pages are junk. Otherwise, you have a crash-recoverable state for those tables as regards those specific pages.
As Steven-san said, I don't want to go this complicated direction. Plus, putting my feet in the user's shoes, I want to try to avoid introducing a new SQL syntax for this kind of performance boost, which requires applications and maintenance scripts and testing.
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 06:30 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-09 15:18 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
@ 2020-11-10 00:59 ` Kyotaro Horiguchi <[email protected]>
2020-11-10 14:16 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-11 03:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 2 replies; 392+ messages in thread
From: Kyotaro Horiguchi @ 2020-11-10 00:59 UTC (permalink / raw)
To: [email protected]; +Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
At Mon, 9 Nov 2020 10:18:08 -0500, Stephen Frost <[email protected]> wrote in
> Greetings,
>
> * [email protected] ([email protected]) wrote:
> > When I consider the use case is the system of data warehouse
> > as described upthread, the size of each table can be large.
> > Thus, changing the status from unlogged to logged (recoverable)
> > takes much time under the current circumstances, which was discussed before.
>
> Ok- so the issue is that, today, we dump all of the table into the WAL
> when we go from unlogged to logged, but as I outlined previously,
> perhaps that's because we're missing a trick there when
> wal_level=minimal. If wal_level=minimal, then it would seem like we
> could lock the table, then sync it and then mark is as logged, which is
FWIW, the following is that, I think it works not only when
wal_level=minimal for SET UNLOGGED, and only works when minimal for
SET LOGGED.
https://www.postgresql.org/message-id/[email protected]
| For fuel(?) of the discussion, I tried a very-quick PoC for in-place
| ALTER TABLE SET LOGGED/UNLOGGED and resulted as attached. After some
| trials of several ways, I drifted to the following way after poking
| several ways.
|
| 1. Flip BM_PERMANENT of active buffers
| 2. adding/removing init fork
| 3. sync files,
| 4. Flip pg_class.relpersistence.
|
| It always skips table copy in the SET UNLOGGED case, and only when
| wal_level=minimal in the SET LOGGED case. Crash recovery seems
| working by some brief testing by hand.
> more-or-less what you're asking to have be effectively done with the
> proposed wal_level=none, but this would be an optimization for all
> existing users of wal_level=minimal who have unlogged tables that they
> want to change to logged, and this works on a per-table basis instead,
> which seems like a better approach than a cluster-wide setting.
>
> > By having the limited window of time,
> > during wal_level=none, I'd like to make wal_level=none work to
> > localize and minimize the burden to guarantee all commands are
> > repeatable. To achieve this, after switching wal_level from none to higher ones,
> > the patch must ensure crash recovery, though.
>
> Perhaps a helper command could be added to ALTER TABLE ALL IN TABLESPACE
> to marked a bunch of unlogged tables over to being logged would be good
> to add too.
I agree to this aspect of the in-place flipping of UNLOGGED.
> > Sorry that my current patch doesn't complete this aspect fully at present
> > but, may I have your opinion about this ?
>
> Presently, my feeling is that we could address this use-case without
> having to introduce a new cluster-wide WAL level, and that's the
> direction I'd want to see this going. Perhaps I'm missing something
> about why the approach I've set forth above wouldn't work, and
> wal_level=none would, but I've not seen it yet.
Couldn't we have something like the following?
ALTER TABLE table1, table2, table3 SET UNLOGGED;
That is, multiple target object specification in ALTER TABLE sttatement.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 06:30 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-09 15:18 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-10 00:59 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
@ 2020-11-10 14:16 ` Stephen Frost <[email protected]>
1 sibling, 0 replies; 392+ messages in thread
From: Stephen Frost @ 2020-11-10 14:16 UTC (permalink / raw)
To: Kyotaro Horiguchi <[email protected]>; +Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Greetings,
* Kyotaro Horiguchi ([email protected]) wrote:
> At Mon, 9 Nov 2020 10:18:08 -0500, Stephen Frost <[email protected]> wrote in
> > Greetings,
> >
> > * [email protected] ([email protected]) wrote:
> > > When I consider the use case is the system of data warehouse
> > > as described upthread, the size of each table can be large.
> > > Thus, changing the status from unlogged to logged (recoverable)
> > > takes much time under the current circumstances, which was discussed before.
> >
> > Ok- so the issue is that, today, we dump all of the table into the WAL
> > when we go from unlogged to logged, but as I outlined previously,
> > perhaps that's because we're missing a trick there when
> > wal_level=minimal. If wal_level=minimal, then it would seem like we
> > could lock the table, then sync it and then mark is as logged, which is
>
> FWIW, the following is that, I think it works not only when
> wal_level=minimal for SET UNLOGGED, and only works when minimal for
> SET LOGGED.
>
> https://www.postgresql.org/message-id/[email protected]
Oh, nice! Very cool that this was already being worked on, apologies
for not seeing that thread.
> | For fuel(?) of the discussion, I tried a very-quick PoC for in-place
> | ALTER TABLE SET LOGGED/UNLOGGED and resulted as attached. After some
> | trials of several ways, I drifted to the following way after poking
> | several ways.
> |
> | 1. Flip BM_PERMANENT of active buffers
> | 2. adding/removing init fork
> | 3. sync files,
> | 4. Flip pg_class.relpersistence.
> |
> | It always skips table copy in the SET UNLOGGED case, and only when
> | wal_level=minimal in the SET LOGGED case. Crash recovery seems
> | working by some brief testing by hand.
Looking over that patch- isn't it missing a necessary FlushBuffers(), to
make sure that any dirty buffers have been written out before the sync
is being done?
Will try to find that thread and review/comment on it there too, if I
can, buf figured I'd point it out here while I have your attention too.
:)
> > more-or-less what you're asking to have be effectively done with the
> > proposed wal_level=none, but this would be an optimization for all
> > existing users of wal_level=minimal who have unlogged tables that they
> > want to change to logged, and this works on a per-table basis instead,
> > which seems like a better approach than a cluster-wide setting.
> >
> > > By having the limited window of time,
> > > during wal_level=none, I'd like to make wal_level=none work to
> > > localize and minimize the burden to guarantee all commands are
> > > repeatable. To achieve this, after switching wal_level from none to higher ones,
> > > the patch must ensure crash recovery, though.
> >
> > Perhaps a helper command could be added to ALTER TABLE ALL IN TABLESPACE
> > to marked a bunch of unlogged tables over to being logged would be good
> > to add too.
>
> I agree to this aspect of the in-place flipping of UNLOGGED.
Yeah, seems like it'd be useful and probably not hard to implement.
> > > Sorry that my current patch doesn't complete this aspect fully at present
> > > but, may I have your opinion about this ?
> >
> > Presently, my feeling is that we could address this use-case without
> > having to introduce a new cluster-wide WAL level, and that's the
> > direction I'd want to see this going. Perhaps I'm missing something
> > about why the approach I've set forth above wouldn't work, and
> > wal_level=none would, but I've not seen it yet.
>
> Couldn't we have something like the following?
>
> ALTER TABLE table1, table2, table3 SET UNLOGGED;
>
> That is, multiple target object specification in ALTER TABLE sttatement.
That requires knowing all the tables ahead of time though, or writing
some pl/pgsql to build up that list. Not hard in general, but having
the 'all in tablespace' would make it a bit easier if you wanted to do
this for effectively all tables in a given database. Having ALTER TABLE
support being given an explicit list of tables does seem like it could
be useful though, so certainly not against that if someone wanted to
implement it.
Thanks,
Stephen
Attachments:
[application/pgp-signature] signature.asc (819B, ../../[email protected]/2-signature.asc)
download
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-09 06:30 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-09 15:18 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-10 00:59 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
@ 2020-11-11 03:07 ` [email protected] <[email protected]>
1 sibling, 0 replies; 392+ messages in thread
From: [email protected] @ 2020-11-11 03:07 UTC (permalink / raw)
To: 'Kyotaro Horiguchi' <[email protected]>; [email protected] <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Horiguchi-San
On Tuesday, November 10, 2020 10:00 AM Kyotaro Horiguchi <[email protected]> wrote:
> FWIW, the following is that, I think it works not only when wal_level=minimal
> for SET UNLOGGED, and only works when minimal for SET LOGGED.
>
> https://www.postgresql.org/message-id/20201002.100621.166891875652013
> [email protected]
>
> | For fuel(?) of the discussion, I tried a very-quick PoC for in-place
> | ALTER TABLE SET LOGGED/UNLOGGED and resulted as attached. After
> some
> | trials of several ways, I drifted to the following way after poking
> | several ways.
> |
> | 1. Flip BM_PERMANENT of active buffers 2. adding/removing init fork 3.
> | sync files, 4. Flip pg_class.relpersistence.
> |
> | It always skips table copy in the SET UNLOGGED case, and only when
> | wal_level=minimal in the SET LOGGED case. Crash recovery seems
> | working by some brief testing by hand.
> I agree to this aspect of the in-place flipping of UNLOGGED.
>
> Couldn't we have something like the following?
> ALTER TABLE table1, table2, table3 SET UNLOGGED;
>
> That is, multiple target object specification in ALTER TABLE sttatement.
I *really* appreciate the 1st patch.
Did you register this patch with the current or next commitfest ?
I cannot find it. We should avoid that this patch misses people's attention.
When I'm available, I'd like to join the review for the patch as well.
Also, I supposed that as long as
something impossible to implement for wal_level=none is not founded,
we could develop both patches in parallel, because both have good points
described in the previous e-mails of this thread.
Best,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
@ 2020-11-19 02:07 ` [email protected] <[email protected]>
2020-11-19 03:45 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-11-19 02:07 UTC (permalink / raw)
To: 'Stephen Frost' <[email protected]>; Magnus Hagander <[email protected]>; +Cc: Robert Haas <[email protected]>; Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Hello
In the past discussion of wal_level=none,
there were some ideas to trace the change of wal_level,
in other words, *stronger mechanism* to check wal_level.
I agree with the idea to have a new monitoring item
and would like to implement those kind of, or one of those ideas for the next patch.
But I'm not sure where is the right place to write the information.
Was the best place the control file ?
On Tuesday, Nov 3, 2020 3:02 AM Stephen Frost <[email protected]> wrote:
> Checking the WAL level certainly seems critical to anything that's reading the
> WAL. We certainly do this already when running as a
> replica:
>
> ereport(WARNING,
> (errmsg("WAL was generated with wal_level=minimal, data may be
> missing"),
> errhint("This happens if you temporarily set wal_level=minimal
> without taking a new base backup.")));
>
> There's definitely a question about if a WARNING there is really sufficient or
> not, considering that you could end up with 'logged'
> tables on the replica that are missing data, but I'm not sure that inventing a
> new, independent, mechanism for checking WAL level changes makes sense.
>
> While pgbackrest backups of a primary wouldn't be impacted, it does support
> backing up from a replica (as do other backup systems, of
> course) and if data that's supposed to be on the replica isn't there because
> someone restarted PG with wal_level=minimal and then flipped it back to
> replica and got the replica to move past that part of the WAL by turning off hot
> standby, replaying, and then turning it back on, then the backup is going to
> also be missing that data.
>
> Perhaps that's where we need to have a stronger mechanism though- that is,
> if we hit the above WARNING, ever, set a flag somewhere that tools can check
> and which we could also check and throw further warnings about. In other
> words, every time this replica is started, we could check for this flag and
> throw the same warning above about how data may be missing, and we could
> have pg_basebackup flat out refuse to back up from a replica where this flag
> has been set (maybe with some kind of override mechanism... maybe not).
> After all, that's where the real issue here is, isn't it?
The first idea is warning that means replica could miss some data.
This is to notify some tools that taking a backup from replica is dangerous.
This can be applied to a change from replica to minimal(or none) and useful
because having the wal_level lowered to minimal does not mean
unclean shutdown or unexpected stoppage but it means a replica might get corrupted.
On Tuesday, Nov 3, 2020 12:28 AM Robert Haas <[email protected]> wrote:
> I'm not exactly sure what that would look like, but suppose we had a feature
> where every time wal_level drops below replica, a counter gets incremented by
> 1, and that counter is saved in the control file. Or maybe when wal_level drops
> below minimal to none. Or maybe there are two counters. Anyway, the idea is
> that if you have a snapshot of the cluster at one time and a snapshot at
> another time, you can see whether anything scary has happened in the middle
> without needing all of the WAL in between.
The second idea is incremental counter that indicates drop of wal_level
from replica to minimal (or like from minimal to none).
Its purpose is to compare the wal_level changes between snapshots.
When any monitoring tools detect any difference of the counter,
we can predict something happened immediately without checking WAL in between.
> > This would also be something that should be exposed as monitoring
> > points (which it could be if it's in pg_control). That is, I can
> > imagine a *lot* of installations that would definitely want an alert
> > to fire if the cluster has ever been started up in a wal_level=none or
> > wal_level=minimal, at least up until the point where somebody has run
> > a new full backup.
>
> I agree with the general idea that it'd be good for anything we do here to be
> made available for monitoring tools to be able to see.
The last one is notification of permanent damage from initial cluster parameter,
although this may be similar to the second one.
This is an indication that shows some part of data are not recovered,
if the cluster was initialized and loaded some data during wal_level=none.
Exposing the monitoring item for tools sounds reasonable for me of course.
Was the control file the best place for the information to implement those kind of ideas ?
What I'm concerned about is that those three items are not necessarily meaningful for all users.
Also, it seems better the size of the control file should be saved
because the size is limited to less than 512 bytes for atomic writes, which is written in a comment.
Here, I didn't say that I'll take all of those ideas into the patch
but this perspective doesn't change whenever we change the content of control file, I would say.
Another aspect unique to the last idea is that
the value will be no use after taking a new full backup.
Thus, I'm not sure if writing that kind of information in the control file is right or not.
Before my implementation,
I would like to get an agreement from the community on this point.
Best,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-19 02:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-19 03:45 ` [email protected] <[email protected]>
2020-11-19 05:24 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-11-19 03:45 UTC (permalink / raw)
To: [email protected] <[email protected]>; 'Stephen Frost' <[email protected]>; Magnus Hagander <[email protected]>; Robert Haas <[email protected]>; +Cc: Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
From: Osumi, Takamichi/大墨 昂道 <[email protected]>
> there were some ideas to trace the change of wal_level,
> in other words, *stronger mechanism* to check wal_level.
> I agree with the idea to have a new monitoring item
> and would like to implement those kind of, or one of those ideas for the next
> patch.
> But I'm not sure where is the right place to write the information.
> Was the best place the control file ?
Yes, I think so (I find nowhere else.)
> On Tuesday, Nov 3, 2020 3:02 AM Stephen Frost <[email protected]>
> wrote:
> > Checking the WAL level certainly seems critical to anything that's reading the
> > WAL. We certainly do this already when running as a
> > replica:
> >
> > ereport(WARNING,
> > (errmsg("WAL was generated with wal_level=minimal, data may be
> > missing"),
> > errhint("This happens if you temporarily set wal_level=minimal
> > without taking a new base backup.")));
> >
> > There's definitely a question about if a WARNING there is really sufficient or
> > not, considering that you could end up with 'logged'
> > tables on the replica that are missing data, but I'm not sure that inventing a
> > new, independent, mechanism for checking WAL level changes makes
> sense.
> >
> > While pgbackrest backups of a primary wouldn't be impacted, it does
> support
> > backing up from a replica (as do other backup systems, of
> > course) and if data that's supposed to be on the replica isn't there because
> > someone restarted PG with wal_level=minimal and then flipped it back to
> > replica and got the replica to move past that part of the WAL by turning off hot
> > standby, replaying, and then turning it back on, then the backup is going to
> > also be missing that data.
> >
> > Perhaps that's where we need to have a stronger mechanism though- that is,
> > if we hit the above WARNING, ever, set a flag somewhere that tools can check
> > and which we could also check and throw further warnings about. In other
> > words, every time this replica is started, we could check for this flag and
> > throw the same warning above about how data may be missing, and we could
> > have pg_basebackup flat out refuse to back up from a replica where this flag
> > has been set (maybe with some kind of override mechanism... maybe not).
> > After all, that's where the real issue here is, isn't it?
> The first idea is warning that means replica could miss some data.
> This is to notify some tools that taking a backup from replica is dangerous.
> This can be applied to a change from replica to minimal(or none) and useful
> because having the wal_level lowered to minimal does not mean
> unclean shutdown or unexpected stoppage but it means a replica might get
> corrupted.
I don't know why WARNING was chosen. I think it should be FATAL, resulting in the standby shutdown, disabling restarting it, and urging the user to rebuild the standby. (I guess that's overreaction because the user may not perform operations that lack WAL while wal_level is minimal.)
> On Tuesday, Nov 3, 2020 12:28 AM Robert Haas <[email protected]>
> wrote:
> > I'm not exactly sure what that would look like, but suppose we had a feature
> > where every time wal_level drops below replica, a counter gets incremented
> by
> > 1, and that counter is saved in the control file. Or maybe when wal_level
> drops
> > below minimal to none. Or maybe there are two counters. Anyway, the idea is
> > that if you have a snapshot of the cluster at one time and a snapshot at
> > another time, you can see whether anything scary has happened in the
> middle
> > without needing all of the WAL in between.
> The second idea is incremental counter that indicates drop of wal_level
> from replica to minimal (or like from minimal to none).
> Its purpose is to compare the wal_level changes between snapshots.
> When any monitoring tools detect any difference of the counter,
> we can predict something happened immediately without checking WAL in
> between.
>
> > > This would also be something that should be exposed as monitoring
> > > points (which it could be if it's in pg_control). That is, I can
> > > imagine a *lot* of installations that would definitely want an alert
> > > to fire if the cluster has ever been started up in a wal_level=none or
> > > wal_level=minimal, at least up until the point where somebody has run
> > > a new full backup.
> >
> > I agree with the general idea that it'd be good for anything we do here to be
> > made available for monitoring tools to be able to see.
> The last one is notification of permanent damage from initial cluster parameter,
> although this may be similar to the second one.
> This is an indication that shows some part of data are not recovered,
> if the cluster was initialized and loaded some data during wal_level=none.
>
> Exposing the monitoring item for tools sounds reasonable for me of course.
> Was the control file the best place for the information to implement those kind
> of ideas ?
> What I'm concerned about is that those three items are not necessarily
> meaningful for all users.
> Also, it seems better the size of the control file should be saved
> because the size is limited to less than 512 bytes for atomic writes, which is
> written in a comment.
> Here, I didn't say that I'll take all of those ideas into the patch
> but this perspective doesn't change whenever we change the content of control
> file, I would say.
> Another aspect unique to the last idea is that
> the value will be no use after taking a new full backup.
> Thus, I'm not sure if writing that kind of information in the control file is right or
> not.
Let's depict the situation. I may be misunderstanding, so any correction would be much welcome. Here, I call the new field wal_level_change_counter, which should be changed to a proper name.
1. wal_level = replica. Take a base backup and store it in $BACKUPDIR/20201119/.
wal_level_change_counter = 0
2. Set wal_level = minimal or none, and restart the instance. Perform some operations.
wal_level_change_counter = 1
3. Set wal_level = replica, and restart the instance.
wal_level_change_counter = 1
4. Some monitoring system compares the values of wal_level_change_counter in $BACKUPDIR/20201119/ and $PGDATA/, and notices the difference (0 and 1 respectively.)
It warns the user that he/she should take a full backup because some WAL may be missing to recover the latest data from the last backup in $BACKUPDIR/20201119/.
But I think this is a separate patch, because the issue already applies to wal_level = minimal.
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-19 02:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 03:45 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-19 05:24 ` [email protected] <[email protected]>
2020-11-19 07:50 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-11-19 05:24 UTC (permalink / raw)
To: [email protected] <[email protected]>; 'Stephen Frost' <[email protected]>; Magnus Hagander <[email protected]>; Robert Haas <[email protected]>; +Cc: Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Hello
On Thursday, Nov 19, 2020 12:45 PM Tsunakawa, Takayuki/綱川 貴之 <[email protected]>
> > On Tuesday, Nov 3, 2020 3:02 AM Stephen Frost <[email protected]>
> > wrote:
> > > Checking the WAL level certainly seems critical to anything that's
> > > reading the WAL. We certainly do this already when running as a
> > > replica:
> > >
> > > ereport(WARNING,
> > > (errmsg("WAL was generated with wal_level=minimal, data may
> > > be missing"),
> > > errhint("This happens if you temporarily set
> > > wal_level=minimal without taking a new base backup.")));
> > >
> > > There's definitely a question about if a WARNING there is really
> > > sufficient or not, considering that you could end up with 'logged'
> > > tables on the replica that are missing data, but I'm not sure that
> > > inventing a new, independent, mechanism for checking WAL level
> > > changes makes
> > sense.
> I don't know why WARNING was chosen. I think it should be FATAL,
> resulting in the standby shutdown, disabling restarting it, and urging the user
> to rebuild the standby. (I guess that's overreaction because the user may
> not perform operations that lack WAL while wal_level is minimal.)
Yeah, I agree that WARNING is not sufficient.
> > The second idea is incremental counter that indicates drop of
> > wal_level from replica to minimal (or like from minimal to none).
> > Its purpose is to compare the wal_level changes between snapshots.
> > When any monitoring tools detect any difference of the counter, we can
> > predict something happened immediately without checking WAL in
> > between.
>
> Let's depict the situation. I may be misunderstanding, so any correction
> would be much welcome. Here, I call the new field
> wal_level_change_counter, which should be changed to a proper name.
>
> 1. wal_level = replica. Take a base backup and store it in
> $BACKUPDIR/20201119/.
> wal_level_change_counter = 0
>
> 2. Set wal_level = minimal or none, and restart the instance. Perform some
> operations.
> wal_level_change_counter = 1
>
> 3. Set wal_level = replica, and restart the instance.
> wal_level_change_counter = 1
>
> 4. Some monitoring system compares the values of
> wal_level_change_counter in $BACKUPDIR/20201119/ and $PGDATA/, and
> notices the difference (0 and 1 respectively.)
> It warns the user that he/she should take a full backup because some WAL
> may be missing to recover the latest data from the last backup in
> $BACKUPDIR/20201119/.
My understanding is completely same as the description Tsunakawa-San wrote above.
> But I think this is a separate patch, because the issue already applies to
> wal_level = minimal.
OK. The range of this patch's responsibility was obscure, but now I'm fine.
I understand that I don't need to incorporate those mechanisms in the new wal_level patch.
Best,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-19 02:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 03:45 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 05:24 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-19 07:50 ` Laurenz Albe <[email protected]>
2020-11-19 10:26 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 16:04 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
0 siblings, 2 replies; 392+ messages in thread
From: Laurenz Albe @ 2020-11-19 07:50 UTC (permalink / raw)
To: [email protected] <[email protected]>; [email protected] <[email protected]>; 'Stephen Frost' <[email protected]>; Magnus Hagander <[email protected]>; Robert Haas <[email protected]>; +Cc: Fujii Masao <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
On Thu, 2020-11-19 at 05:24 +0000, [email protected] wrote:
> > > > ereport(WARNING,
> > > > (errmsg("WAL was generated with wal_level=minimal, data may
> > > > be missing"),
> > > > errhint("This happens if you temporarily set
> > > > wal_level=minimal without taking a new base backup.")));
> > > > There's definitely a question about if a WARNING there is really
> > > > sufficient or not, considering that you could end up with 'logged'
> > > > tables on the replica that are missing data, but I'm not sure that
> > > > inventing a new, independent, mechanism for checking WAL level
> > > > changes makes
> > > sense.
> >
> > I don't know why WARNING was chosen. I think it should be FATAL,
> > resulting in the standby shutdown, disabling restarting it, and urging the user
> > to rebuild the standby. (I guess that's overreaction because the user may
> > not perform operations that lack WAL while wal_level is minimal.)
>
> Yeah, I agree that WARNING is not sufficient.
I missed that this is only a warning when I looked at it before.
Yes, it should be a fatal error.
I think that there should two patches: one that turns this warning into
a FATAL and should be backpatched. If you change the test to
ControlFile->wal_level <= WAL_LEVEL_MINIMAL
it will automatically work for your new feature too.
Then your new wal_level would be a second patch only for HEAD.
With that, the only remaining consideration with this patch is the danger
that enabling wal_level=none without taking a backup before can lead to
data loss. But that is intended, so I think that an unmistakable warning
in the documentation would be good enough.
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-19 02:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 03:45 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 05:24 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
@ 2020-11-19 10:26 ` [email protected] <[email protected]>
1 sibling, 0 replies; 392+ messages in thread
From: [email protected] @ 2020-11-19 10:26 UTC (permalink / raw)
To: 'Laurenz Albe' <[email protected]>; [email protected] <[email protected]>; 'Stephen Frost' <[email protected]>; Magnus Hagander <[email protected]>; Robert Haas <[email protected]>; +Cc: Fujii Masao <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Hello, Laurenz
On Thursday, Nov19, 2020 4:50 PM Laurenz Albe <[email protected]> wrote
> On Thu, 2020-11-19 at 05:24 +0000, [email protected] wrote:
> > > > > ereport(WARNING,
> > > > > (errmsg("WAL was generated with wal_level=minimal, data
> > > > > may be missing"),
> > > > > errhint("This happens if you temporarily set
> > > > > wal_level=minimal without taking a new base backup."))); There's
> > > > > definitely a question about if a WARNING there is really
> > > > > sufficient or not, considering that you could end up with 'logged'
> > > > > tables on the replica that are missing data, but I'm not sure
> > > > > that inventing a new, independent, mechanism for checking WAL
> > > > > level changes makes
> > > > sense.
> > >
> > > I don't know why WARNING was chosen. I think it should be FATAL,
> > > resulting in the standby shutdown, disabling restarting it, and
> > > urging the user to rebuild the standby. (I guess that's
> > > overreaction because the user may not perform operations that lack
> > > WAL while wal_level is minimal.)
> >
> > Yeah, I agree that WARNING is not sufficient.
>
> I missed that this is only a warning when I looked at it before.
> Yes, it should be a fatal error.
>
> I think that there should two patches: one that turns this warning into a
> FATAL and should be backpatched. If you change the test to
>
> ControlFile->wal_level <= WAL_LEVEL_MINIMAL
>
> it will automatically work for your new feature too.
> Then your new wal_level would be a second patch only for HEAD.
Yeah, this suggestion to divide the patch into two sounds really good.
Thank you. I'll post separated patches next time.
>
> With that, the only remaining consideration with this patch is the danger that
> enabling wal_level=none without taking a backup before can lead to data loss.
> But that is intended, so I think that an unmistakable warning in the
> documentation would be good enough.
Yes, thank you for reviewing the documents in the patch.
Best,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-19 02:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 03:45 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 05:24 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
@ 2020-11-19 16:04 ` Stephen Frost <[email protected]>
2020-11-20 00:22 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: Stephen Frost @ 2020-11-19 16:04 UTC (permalink / raw)
To: Laurenz Albe <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; Magnus Hagander <[email protected]>; Robert Haas <[email protected]>; Fujii Masao <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Greetings,
* Laurenz Albe ([email protected]) wrote:
> On Thu, 2020-11-19 at 05:24 +0000, [email protected] wrote:
> > > > > ereport(WARNING,
> > > > > (errmsg("WAL was generated with wal_level=minimal, data may
> > > > > be missing"),
> > > > > errhint("This happens if you temporarily set
> > > > > wal_level=minimal without taking a new base backup.")));
> > > > > There's definitely a question about if a WARNING there is really
> > > > > sufficient or not, considering that you could end up with 'logged'
> > > > > tables on the replica that are missing data, but I'm not sure that
> > > > > inventing a new, independent, mechanism for checking WAL level
> > > > > changes makes
> > > > sense.
> > >
> > > I don't know why WARNING was chosen. I think it should be FATAL,
> > > resulting in the standby shutdown, disabling restarting it, and urging the user
> > > to rebuild the standby. (I guess that's overreaction because the user may
> > > not perform operations that lack WAL while wal_level is minimal.)
> >
> > Yeah, I agree that WARNING is not sufficient.
>
> I missed that this is only a warning when I looked at it before.
> Yes, it should be a fatal error.
Yeah, the more that I think about it, the more that I tend to agree with
this. Does anyone want to argue against changing this into a FATAL..?
Thanks,
Stephen
Attachments:
[application/pgp-signature] signature.asc (819B, ../../[email protected]/2-signature.asc)
download
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-19 02:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 03:45 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 05:24 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-11-19 16:04 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
@ 2020-11-20 00:22 ` Kyotaro Horiguchi <[email protected]>
2020-11-20 00:32 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: Kyotaro Horiguchi @ 2020-11-20 00:22 UTC (permalink / raw)
To: [email protected]; +Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
At Thu, 19 Nov 2020 11:04:17 -0500, Stephen Frost <[email protected]> wrote in
> Greetings,
>
> * Laurenz Albe ([email protected]) wrote:
> > On Thu, 2020-11-19 at 05:24 +0000, [email protected] wrote:
> > > > > > ereport(WARNING,
> > > > > > (errmsg("WAL was generated with wal_level=minimal, data may
> > > > > > be missing"),
> > > > > > errhint("This happens if you temporarily set
> > > > > > wal_level=minimal without taking a new base backup.")));
> > > > > > There's definitely a question about if a WARNING there is really
> > > > > > sufficient or not, considering that you could end up with 'logged'
> > > > > > tables on the replica that are missing data, but I'm not sure that
> > > > > > inventing a new, independent, mechanism for checking WAL level
> > > > > > changes makes
> > > > > sense.
> > > >
> > > > I don't know why WARNING was chosen. I think it should be FATAL,
> > > > resulting in the standby shutdown, disabling restarting it, and urging the user
> > > > to rebuild the standby. (I guess that's overreaction because the user may
> > > > not perform operations that lack WAL while wal_level is minimal.)
> > >
> > > Yeah, I agree that WARNING is not sufficient.
> >
> > I missed that this is only a warning when I looked at it before.
> > Yes, it should be a fatal error.
>
> Yeah, the more that I think about it, the more that I tend to agree with
> this. Does anyone want to argue against changing this into a FATAL..?
I don't come up with a use case where someone needs to set
wal_level=minimal for archive recovery. So +1 to change it to FATAL.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-19 02:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 03:45 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 05:24 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-11-19 16:04 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-20 00:22 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
@ 2020-11-20 00:32 ` [email protected] <[email protected]>
2020-11-20 01:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-11-20 00:32 UTC (permalink / raw)
To: 'Kyotaro Horiguchi' <[email protected]>; [email protected] <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
From: Kyotaro Horiguchi <[email protected]>
> At Thu, 19 Nov 2020 11:04:17 -0500, Stephen Frost <[email protected]>
> > * Laurenz Albe ([email protected]) wrote:
> > > I missed that this is only a warning when I looked at it before.
> > > Yes, it should be a fatal error.
> >
> > Yeah, the more that I think about it, the more that I tend to agree with
> > this. Does anyone want to argue against changing this into a FATAL..?
>
> I don't come up with a use case where someone needs to set
> wal_level=minimal for archive recovery. So +1 to change it to FATAL.
Thank you all. I'd like to give Osumi-san an opportunity to write a patch and showing the evidence of successful test if you don't mind. He is very young and newbie to Postgres, so even a small contribution would encourage him to make further contributions.
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-19 02:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 03:45 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 05:24 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-11-19 16:04 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-20 00:22 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-11-20 00:32 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-20 01:19 ` [email protected] <[email protected]>
2020-11-20 16:03 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-11-20 01:19 UTC (permalink / raw)
To: [email protected] <[email protected]>; 'Kyotaro Horiguchi' <[email protected]>; [email protected] <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Hello
On Friday, Nov 20, 2020 9:33 AM Tsunakawa, Takayuki <[email protected]> wrote:
> From: Kyotaro Horiguchi <[email protected]>
> > At Thu, 19 Nov 2020 11:04:17 -0500, Stephen Frost <[email protected]>
> > > * Laurenz Albe ([email protected]) wrote:
> > > > I missed that this is only a warning when I looked at it before.
> > > > Yes, it should be a fatal error.
> > >
> > > Yeah, the more that I think about it, the more that I tend to agree
> > > with this. Does anyone want to argue against changing this into a
> FATAL..?
> >
> > I don't come up with a use case where someone needs to set
> > wal_level=minimal for archive recovery. So +1 to change it to FATAL.
It seems we reached the agreement for this fix.
> Thank you all. I'd like to give Osumi-san an opportunity to write a patch and
> showing the evidence of successful test if you don't mind. He is very young
> and newbie to Postgres, so even a small contribution would encourage him to
> make further contributions.
Sure. Let me do that, including the test.
Best,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
2020-11-02 15:35 ` Re: Disable WAL logging to speed up data loading Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-19 02:07 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 03:45 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 05:24 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-11-19 16:04 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-20 00:22 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-11-20 00:32 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 01:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-20 16:03 ` Stephen Frost <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Stephen Frost @ 2020-11-20 16:03 UTC (permalink / raw)
To: [email protected] <[email protected]>; +Cc: [email protected] <[email protected]>; 'Kyotaro Horiguchi' <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Greetings,
* [email protected] ([email protected]) wrote:
> On Friday, Nov 20, 2020 9:33 AM Tsunakawa, Takayuki <[email protected]> wrote:
> > From: Kyotaro Horiguchi <[email protected]>
> > > At Thu, 19 Nov 2020 11:04:17 -0500, Stephen Frost <[email protected]>
> > > > * Laurenz Albe ([email protected]) wrote:
> > > > > I missed that this is only a warning when I looked at it before.
> > > > > Yes, it should be a fatal error.
> > > >
> > > > Yeah, the more that I think about it, the more that I tend to agree
> > > > with this. Does anyone want to argue against changing this into a
> > FATAL..?
> > >
> > > I don't come up with a use case where someone needs to set
> > > wal_level=minimal for archive recovery. So +1 to change it to FATAL.
> It seems we reached the agreement for this fix.
>
> > Thank you all. I'd like to give Osumi-san an opportunity to write a patch and
> > showing the evidence of successful test if you don't mind. He is very young
> > and newbie to Postgres, so even a small contribution would encourage him to
> > make further contributions.
> Sure. Let me do that, including the test.
That all sounds good to me. I would recommend starting a new thread on
-hackers with the patch, once it's ready, since it's really independent
from the topic of this thread.
Thanks,
Stephen
Attachments:
[application/pgp-signature] signature.asc (819B, ../../[email protected]/2-signature.asc)
download
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-29 10:21 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-02 15:28 ` Re: Disable WAL logging to speed up data loading Robert Haas <[email protected]>
@ 2020-11-17 01:45 ` [email protected] <[email protected]>
1 sibling, 0 replies; 392+ messages in thread
From: [email protected] @ 2020-11-17 01:45 UTC (permalink / raw)
To: 'Robert Haas' <[email protected]>; +Cc: Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
From: Robert Haas <[email protected]>
> I'm also concerned about the way that this proposed feature interacts with
> incremental backup capabilities that already exist in tools like pgBackRest,
> EDB's BART, pg_probackup, and future things we might want to introduce into
> core, along the lines of what I have previously proposed. Now, I think
> pgBackRest uses only timestamps and checksums, so it probably doesn't care,
> but some of the other solutions rely on WAL-scanning to gather a list of
> changed blocks. I guess there's no reason that they can't notice the wal_level
> being changed and do the right thing; they should probably have that kind of
> capability already. Still, it strikes me that it might be useful if we had a stronger
> mechanism.
Having a quick look, those backup tools seem to require setting wal_level to replica or higher. That's no wonder, because recovering the database needs WAL for non-relation resources such as pg_control and relation map. So, I think wal_level = none won't introduce new issues (compared to wal_level = minimal, which also can lack WAL records for some data updates.)
> By the way, another problem here is that some AMs - e.g. GiST, IIRC - use LSNs
> to figure out whether a block has changed. For temporary and unlogged tables,
> we use "fake" LSNs that are generated using a counter, but that approach only
> works because such relations are never really WAL-logged. Mixing fake LSNs
> and real LSNs will break stuff, and not bumping the LSN when the page
> changes probably will, too.
Unlogged GiST indexes use fake LSNs that are instance-wide. Unlogged temporary GiST indexes use backend-local sequence values. Other unlogged and temporary relations don't set LSNs on pages. So, I think it's enough to call GetFakeLSNForUnloggedRel() when wal_level = none as well.
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
@ 2020-11-16 07:19 ` [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-11-16 07:19 UTC (permalink / raw)
To: 'Fujii Masao' <[email protected]>; Laurenz Albe <[email protected]>; [email protected] <[email protected]>; Kyotaro Horiguchi <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>
Hi
On Thursday, October 29, 2020 11:42 AM Fujii Masao <[email protected]> wrote:
> BTW, with the patch, I observed that PREPARE TRANSACTION and COMMIT
> PREPARED caused assertion failure in my env, as I pointed upthread.
>
> How does the patch handle other feature depending on the existence of WAL,
> e.g., pg_logical_emit_message()?
I've updated the first patch, based on comments
from both Tsunakwa-San and Fujii-San mainly.
I'll take other comments in the next patch.
(Note that this patch passes make check-world but
doesn't pass installcheck-world yet.)
The assertion failure Fujii-San reported in the past has been protected by
adding a check to detect whether PREPARE TRANSACTION is issued
when wal_level=none or not in the v02.
Meanwhile, I didn't change the code for COMMIT PREPARED
because prohibiting usage of PREPARE TRANSACTION
means user cannot use COMMIT PREPARED as well.
I learnt this way of modification from the case that when max_prepared_transaction
is set to zero, PREPARE TRANSACTION cannot be used because of wa_level check,
while issuing COMMIT TRANSACTION itself doesn't claim wal_level.
Just prohibiting PREPARE TRANSACTION seemed OK for me.
As for pg_resetwal (and other commands like pg_rewind),
I didn't make any change. pg_resetwal is used to make corrupted server
start up again as a *last* resort by guessing the content of the control file,
while wal_level=none is designed never to make
the server start again when any unexpected crash is detected.
Here, the documentation in the patch about wal_level=none
requests user to recreate the whole cluster again
when such a corruption of the cluster happens. Thus, it's not natural to think
that user of wal_level=none will continue to use the coruppted cluster forcibly
by applying pg_resetwal. This is the reason I made no fix of pg_resetwal.
In terms of other commands, I don't think there was a need to fix.
By the way, I'm not sure why functions related to replication origin
(e.g. pg_replication_origin_create) doesn't have a check of
wal_level. It can be used when wal_level < logical even though
their purposes are to safely keep track of replication progress.
Did it mean something special to execute such function when wal_level < logical ?
In the patch, I added an error check on this point.
Another similar case is that
there's no test to check wal_level for pg_logical_emit_message.
In my humble opinion, pg_logical_emit_message should not be used
when wal_level <= minimal. I didn't think that
without setting up a slot for logical replication
(with the restriction that user cannot create a slot by
pg_create_physical_replication_slot when wal_level < replica),
plugins will utilize message from pg_logical_emit_message.
Or, if there is a slot that has been created before
restarting the server to turn on wal_level=none,
I cannot get the worth to execute the function
because other kinds of WAL are not issued.
Thus, I prohibited the usage of pg_logical_emit_message this time.
Did it make sense ?
Best,
Takamichi Osumi
Attachments:
[application/octet-stream] disable_WAL_logging_v02.patch (16.1K, ../../OSBPR01MB48884E14FFFB8FBD49F9C8BAEDE30@OSBPR01MB4888.jpnprd01.prod.outlook.com/2-disable_WAL_logging_v02.patch)
download | inline diff:
From 187fd4476422e95f079bba69d1e1e047bc5edb79 Mon Sep 17 00:00:00 2001
From: Osumi Takamichi <[email protected]>
Date: Mon, 16 Nov 2020 05:03:19 +0000
Subject: [PATCH v02] new wal_level to disable WAL logging
In order to speed up the performance, especially
for bulk data loading or pg_dumpall, this feature turns off
generation of WAL except for XLOG resources.
This means we gain this speed-up even at the cost of crash recovery.
During the operation of this new wal_level,
an unexpected stoppage or shutdown of the server
makes the whole cluster corrupted and unrecoverable.
Therefore, taking a full backup before and after the operation is a must.
Author: Takamichi Osumi <[email protected]>
Reviewed-by: Tsunakawa, Takayuki <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Reviewed-by: Ashutosh Bapat <[email protected]>
Discussion: https://www.postgresql.org/message-id/TYAPR01MB29901EBE5A3ACCE55BA99186FE320%40TYAPR01MB2990.jpnprd01.prod.outlook.com
---
doc/src/sgml/config.sgml | 20 ++++++++++++++++--
doc/src/sgml/perform.sgml | 13 +++++++++---
src/backend/access/rmgrdesc/xlogdesc.c | 1 +
src/backend/access/transam/varsup.c | 2 +-
src/backend/access/transam/xlog.c | 28 ++++++++++++++++++++++++--
src/backend/access/transam/xloginsert.c | 7 +++++++
src/backend/postmaster/postmaster.c | 6 +++---
src/backend/replication/logical/logicalfuncs.c | 4 ++++
src/backend/replication/logical/origin.c | 4 ++++
src/backend/tcop/utility.c | 3 +++
src/backend/utils/misc/postgresql.conf.sample | 6 ++++--
src/bin/pg_controldata/pg_controldata.c | 2 ++
src/include/access/xlog.h | 4 +++-
src/include/access/xlogdefs.h | 2 +-
src/include/utils/rel.h | 3 ++-
15 files changed, 89 insertions(+), 16 deletions(-)
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index f043433..3111a4d 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -2591,7 +2591,15 @@ include_dir 'conf.d'
data to support WAL archiving and replication, including running
read-only queries on a standby server. <literal>minimal</literal> removes all
logging except the information required to recover from a crash or
- immediate shutdown. Finally,
+ immediate shutdown. <literal>none</literal> generates no WAL
+ except for ones related to transaction resources such as indication of checkpoint
+ or the end of recovery. This means that the amount of WAL during <literal>none</literal>
+ operation could be much less than that of <literal>minimal</literal> for ordinal operation.
+ Intrinsically, the purpose of <literal>none</literal>
+ is to accelerate data bulk loading at the expense of recovery.
+ Accordingly, note that crash during <literal>none</literal> makes
+ the whole cluster corrupted and unrecoverable. Therefore, never use this mode
+ unless the operation during the mode is repeatable and the cluster is backed up. Finally,
<literal>logical</literal> adds information necessary to support logical
decoding. Each level includes the information logged at all lower
levels. This parameter can only be set at server start.
@@ -2615,6 +2623,13 @@ include_dir 'conf.d'
data from a base backup and the WAL logs, so <literal>replica</literal> or
higher must be used to enable WAL archiving
(<xref linkend="guc-archive-mode"/>) and streaming replication.
+ In the same way, <literal>none</literal> does not create WAL logs in principle.
+ Therefore, this <varname>wal_level</varname> can be used to maximize the speed of data loading.
+ For example, bulk data loading or version upgrade using pg_dumpall.
+ On the other hand, an unexpected crash of the server makes the database cluster
+ inconsistent and never able to restart. For that reason, before utilizing this level,
+ get a full backup of both the cluster itself and the entire operations
+ that are done under the condition that <varname>wal_level</varname> is <literal>none</literal>.
</para>
<para>
In <literal>logical</literal> level, the same information is logged as
@@ -3372,7 +3387,8 @@ include_dir 'conf.d'
changed without leaving archiving mode.
This parameter can only be set at server start.
<varname>archive_mode</varname> cannot be enabled when
- <varname>wal_level</varname> is set to <literal>minimal</literal>.
+ <varname>wal_level</varname> is set to <literal>none</literal> or
+ <literal>minimal</literal>.
</para>
</listitem>
</varlistentry>
diff --git a/doc/src/sgml/perform.sgml b/doc/src/sgml/perform.sgml
index 117a1f7..07d47d4 100644
--- a/doc/src/sgml/perform.sgml
+++ b/doc/src/sgml/perform.sgml
@@ -1741,10 +1741,17 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
new base backup after the load has completed than to process a large
amount of incremental WAL data. To prevent incremental WAL logging
while loading, disable archiving and streaming replication, by setting
- <xref linkend="guc-wal-level"/> to <literal>minimal</literal>,
+ <xref linkend="guc-wal-level"/> to either <literal>none</literal>
+ or <literal>minimal</literal>,
<xref linkend="guc-archive-mode"/> to <literal>off</literal>, and
<xref linkend="guc-max-wal-senders"/> to zero.
- But note that changing these settings requires a server restart.
+ Changing <literal>wal_level</literal> to <literal>none</literal>
+ is extremely performance-oriented feature. Therefore, paying
+ a careful attention that a crash during the data loading causes
+ corruption of the whole cluster is needed. When it happens,
+ the server will not restart again any more and the administrator
+ needs to set up the cluster from the full backup.
+ Also, note that changing these settings requires a server restart.
</para>
<para>
@@ -1810,7 +1817,7 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
If using WAL archiving or streaming replication, consider disabling
them during the restore. To do that, set <varname>archive_mode</varname>
to <literal>off</literal>,
- <varname>wal_level</varname> to <literal>minimal</literal>, and
+ <varname>wal_level</varname> to <literal>minimal</literal> or <literal>none</literal>, and
<varname>max_wal_senders</varname> to zero before loading the dump.
Afterwards, set them back to the right values and take a fresh
base backup.
diff --git a/src/backend/access/rmgrdesc/xlogdesc.c b/src/backend/access/rmgrdesc/xlogdesc.c
index 3200f77..8293b3b 100644
--- a/src/backend/access/rmgrdesc/xlogdesc.c
+++ b/src/backend/access/rmgrdesc/xlogdesc.c
@@ -25,6 +25,7 @@
* GUC support
*/
const struct config_enum_entry wal_level_options[] = {
+ {"none", WAL_LEVEL_NONE, false},
{"minimal", WAL_LEVEL_MINIMAL, false},
{"replica", WAL_LEVEL_REPLICA, false},
{"archive", WAL_LEVEL_REPLICA, true}, /* deprecated */
diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c
index a4944fa..712943a 100644
--- a/src/backend/access/transam/varsup.c
+++ b/src/backend/access/transam/varsup.c
@@ -368,7 +368,7 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid)
* within 3M transactions of data loss. This leaves lots of room for the
* DBA to fool around fixing things in a standalone backend, while not
* being significant compared to total XID space. (VACUUM requires an XID
- * if it truncates at wal_level!=minimal. "VACUUM (ANALYZE)", which a DBA
+ * if it truncates at wal_level<=minimal. "VACUUM (ANALYZE)", which a DBA
* might do by reflex, assigns an XID. Hence, we had better be sure
* there's lots of XIDs left...) Also, at default BLCKSZ, this leaves two
* completely-idle segments. In the event of edge-case bugs involving
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index aa63f37..559cfe1 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4937,6 +4937,21 @@ DataChecksumsEnabled(void)
}
/*
+ * Returns the latest LSN.
+ */
+XLogRecPtr
+GetLatestCheckPointLSN(void)
+{
+ XLogRecPtr latestLSN;
+
+ LWLockAcquire(ControlFileLock, LW_SHARED);
+ latestLSN = ControlFile->checkPoint;
+ LWLockRelease(ControlFileLock);
+
+ return latestLSN;
+}
+
+/*
* Returns a fake LSN for unlogged relations.
*
* Each call generates an LSN that is greater than any previous value
@@ -6254,10 +6269,10 @@ CheckRequiredParameterValues(void)
* For archive recovery, the WAL must be generated with at least 'replica'
* wal_level.
*/
- if (ArchiveRecoveryRequested && ControlFile->wal_level == WAL_LEVEL_MINIMAL)
+ if (ArchiveRecoveryRequested && ControlFile->wal_level <= WAL_LEVEL_MINIMAL)
{
ereport(WARNING,
- (errmsg("WAL was generated with wal_level=minimal, data may be missing"),
+ (errmsg("WAL was generated with wal_level<=minimal, data may be missing"),
errhint("This happens if you temporarily set wal_level=minimal without taking a new base backup.")));
}
@@ -6328,6 +6343,15 @@ StartupXLOG(void)
CurrentResourceOwner = AuxProcessResourceOwner;
/*
+ * Detect if the server previously crashed under wal_level='none' or not.
+ */
+ if (ControlFile->wal_level == WAL_LEVEL_NONE &&
+ (ControlFile->state != DB_SHUTDOWNED && ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY))
+ ereport(ERROR,
+ (errmsg("detected an unexpected server shutdown when WAL logging was disabled"),
+ errhint("It looks like you need to deploy a new cluster from your full backup again.")));
+
+ /*
* Check that contents look valid.
*/
if (!XRecOffIsValid(ControlFile->checkPoint))
diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c
index 1f0e4e0..8d6b875 100644
--- a/src/backend/access/transam/xloginsert.c
+++ b/src/backend/access/transam/xloginsert.c
@@ -449,6 +449,13 @@ XLogInsert(RmgrId rmid, uint8 info)
return EndPos;
}
+ /* Issues WAL only for XLOG resources */
+ if (wal_level == WAL_LEVEL_NONE && rmid != RM_XLOG_ID)
+ {
+ XLogResetInsertion();
+ return GetLatestCheckPointLSN();
+ }
+
do
{
XLogRecPtr RedoRecPtr;
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index b7799ed..27e4475 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -903,10 +903,10 @@ PostmasterMain(int argc, char *argv[])
ReservedBackends, MaxConnections);
ExitPostmaster(1);
}
- if (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level == WAL_LEVEL_MINIMAL)
+ if (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level <= WAL_LEVEL_MINIMAL)
ereport(ERROR,
- (errmsg("WAL archival cannot be enabled when wal_level is \"minimal\"")));
- if (max_wal_senders > 0 && wal_level == WAL_LEVEL_MINIMAL)
+ (errmsg("WAL archival cannot be enabled when wal_level is \"none\" or \"\"minimal")));
+ if (max_wal_senders > 0 && wal_level <= WAL_LEVEL_MINIMAL)
ereport(ERROR,
(errmsg("WAL streaming (max_wal_senders > 0) requires wal_level \"replica\" or \"logical\"")));
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index b99c94e..a3151fa 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -404,6 +404,10 @@ pg_logical_emit_message_bytea(PG_FUNCTION_ARGS)
bytea *data = PG_GETARG_BYTEA_PP(2);
XLogRecPtr lsn;
+ if (wal_level < WAL_LEVEL_REPLICA)
+ ereport(ERROR,
+ errmsg("propagating a message requires wal_level \"replica\" or \"logical\""));
+
lsn = LogLogicalMessage(prefix, VARDATA_ANY(data), VARSIZE_ANY_EXHDR(data),
transactional);
PG_RETURN_LSN(lsn);
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index 1b22031..5e1f705 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -192,6 +192,10 @@ replorigin_check_prerequisites(bool check_slots, bool recoveryOK)
(errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
errmsg("cannot manipulate replication origins during recovery")));
+ if (wal_level < WAL_LEVEL_REPLICA)
+ ereport(ERROR,
+ errmsg("creating replication origins requires wal_level \"replica\" or \"logical\""));
+
}
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index f398027..0f7597b 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -625,6 +625,9 @@ standard_ProcessUtility(PlannedStmt *pstmt,
break;
case TRANS_STMT_PREPARE:
+ if (wal_level == WAL_LEVEL_NONE)
+ ereport(ERROR,
+ errmsg("cannot execute PREPARE TRANSACTION when WAL logging is disabled"));
if (!PrepareTransactionBlock(stmt->gid))
{
/* report unsuccessful commit in qc */
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 9cb571f..9bf89e5 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -196,8 +196,10 @@
# - Settings -
-#wal_level = replica # minimal, replica, or logical
- # (change requires restart)
+#wal_level = replica # none, minimal, replica, or logical
+ # (change requires restart.
+ # choosing the none wal_level
+ # can cause unrecoverable data corruption)
#fsync = on # flush data to disk for crash safety
# (turning this off can cause
# unrecoverable data corruption)
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 3e00ac0..90ec0dc 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -74,6 +74,8 @@ wal_level_str(WalLevel wal_level)
{
switch (wal_level)
{
+ case WAL_LEVEL_NONE:
+ return "none";
case WAL_LEVEL_MINIMAL:
return "minimal";
case WAL_LEVEL_REPLICA:
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 221af87..b8cffec 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -161,7 +161,8 @@ extern int XLogArchiveMode;
/* WAL levels */
typedef enum WalLevel
{
- WAL_LEVEL_MINIMAL = 0,
+ WAL_LEVEL_NONE = 0,
+ WAL_LEVEL_MINIMAL,
WAL_LEVEL_REPLICA,
WAL_LEVEL_LOGICAL
} WalLevel;
@@ -319,6 +320,7 @@ extern void UpdateControlFile(void);
extern uint64 GetSystemIdentifier(void);
extern char *GetMockAuthenticationNonce(void);
extern bool DataChecksumsEnabled(void);
+extern XLogRecPtr GetLatestCheckPointLSN(void);
extern XLogRecPtr GetFakeLSNForUnloggedRel(void);
extern Size XLOGShmemSize(void);
extern void XLOGShmemInit(void);
diff --git a/src/include/access/xlogdefs.h b/src/include/access/xlogdefs.h
index e1f5812..197ad06 100644
--- a/src/include/access/xlogdefs.h
+++ b/src/include/access/xlogdefs.h
@@ -59,7 +59,7 @@ typedef uint16 RepOriginId;
/*
* Because O_DIRECT bypasses the kernel buffers, and because we never
- * read those buffers except during crash recovery or if wal_level != minimal,
+ * read those buffers except during crash recovery or if wal_level <= minimal,
* it is a win to use it in all cases where we sync on each write(). We could
* allow O_DIRECT with fsync(), but it is unclear if fsync() could process
* writes not buffered in the kernel. Also, O_DIRECT is never enough to force
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index c5ffea4..a9f6af1 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -561,10 +561,11 @@ typedef struct ViewOptions
* RelFileNode" in src/backend/access/transam/README.
*/
#define RelationNeedsWAL(relation) \
+ (wal_level != WAL_LEVEL_NONE && \
((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \
(XLogIsNeeded() || \
(relation->rd_createSubid == InvalidSubTransactionId && \
- relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
+ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))))
/*
* RelationUsesLocalBuffers
--
1.8.3.1
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-19 07:50 ` [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-11-19 07:50 UTC (permalink / raw)
To: [email protected] <[email protected]>; +Cc: 'Fujii Masao' <[email protected]>; Laurenz Albe <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
(1)
#define RelationNeedsWAL(relation) \
+ (wal_level != WAL_LEVEL_NONE && \
((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \
(XLogIsNeeded() || \
(relation->rd_createSubid == InvalidSubTransactionId && \
- relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
+ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))))
You can remove one pair of parentheses for readability as follows:
#define RelationNeedsWAL(relation) \
+ (wal_level != WAL_LEVEL_NONE && \
(relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \
(XLogIsNeeded() || \
(relation->rd_createSubid == InvalidSubTransactionId && \
- relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
+ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
(2)
/*
+ * Detect if the server previously crashed under wal_level='none' or not.
+ */
+ if (ControlFile->wal_level == WAL_LEVEL_NONE &&
+ (ControlFile->state != DB_SHUTDOWNED && ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY))
+ ereport(ERROR,
+ (errmsg("detected an unexpected server shutdown when WAL logging was disabled"),
+ errhint("It looks like you need to deploy a new cluster from your full backup again.")));
+
+ /*
* Check that contents look valid.
*/
if (!XRecOffIsValid(ControlFile->checkPoint))
I think the above safeguard should be placed right before the following code, because it's better to first check control file contents and emit the message for the previous shutdown state.
#ifdef XLOG_REPLAY_DELAY
if (ControlFile->state != DB_SHUTDOWNED)
pg_usleep(60000000L);
#endif
(3)
@@ -449,6 +449,13 @@ XLogInsert(RmgrId rmid, uint8 info)
return EndPos;
}
+ /* Issues WAL only for XLOG resources */
+ if (wal_level == WAL_LEVEL_NONE && rmid != RM_XLOG_ID)
+ {
+ XLogResetInsertion();
+ return GetLatestCheckPointLSN();
+ }
It should be correct to use GetXLogInsertRecPtr() instead of GetLatestCheckPointLSN(), because what XLogInsert() should return is the end position of last WAL record inserted (= start position of next WAL).
Why don't we add transaction completion WAL records? That is, add "rmid != RM_XACT_ID" to the if condition. What we really want to eliminate for performance is the data modification WAL records. This might allow us to insert special checks to prevent PREPARE TRANSACTION and other stuff.
(4)
@@ -404,6 +404,10 @@ pg_logical_emit_message_bytea(PG_FUNCTION_ARGS)
bytea *data = PG_GETARG_BYTEA_PP(2);
XLogRecPtr lsn;
+ if (wal_level < WAL_LEVEL_REPLICA)
+ ereport(ERROR,
+ errmsg("propagating a message requires wal_level \"replica\" or \"logical\""));
+
lsn = LogLogicalMessage(prefix, VARDATA_ANY(data), VARSIZE_ANY_EXHDR(data),
transactional);
PG_RETURN_LSN(lsn);
@@ -192,6 +192,10 @@ replorigin_check_prerequisites(bool check_slots, bool recoveryOK)
(errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
errmsg("cannot manipulate replication origins during recovery")));
+ if (wal_level < WAL_LEVEL_REPLICA)
+ ereport(ERROR,
+ errmsg("creating replication origins requires wal_level \"replica\" or \"logical\""));
+
}
@@ -625,6 +625,9 @@ standard_ProcessUtility(PlannedStmt *pstmt,
break;
case TRANS_STMT_PREPARE:
+ if (wal_level == WAL_LEVEL_NONE)
+ ereport(ERROR,
+ errmsg("cannot execute PREPARE TRANSACTION when WAL logging is disabled"));
What happens without these checks?
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-20 12:47 ` [email protected] <[email protected]>
2020-11-23 03:17 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-23 03:18 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
0 siblings, 2 replies; 392+ messages in thread
From: [email protected] @ 2020-11-20 12:47 UTC (permalink / raw)
To: [email protected] <[email protected]>; +Cc: 'Fujii Masao' <[email protected]>; Laurenz Albe <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Hi
This time, I updated my patch to address comments below only.
Please have a look at updated one.
On Thursday, Nov 19, 2020 4:51 PM Tsunakawa, Takayuki <[email protected]>
> (1)
> #define RelationNeedsWAL(relation)
> \
> + (wal_level != WAL_LEVEL_NONE &&
> \
> ((relation)->rd_rel->relpersistence ==
> RELPERSISTENCE_PERMANENT && \
> (XLogIsNeeded() ||
> \
> (relation->rd_createSubid == InvalidSubTransactionId &&
> \
> - relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
> + relation->rd_firstRelfilenodeSubid ==
> InvalidSubTransactionId))))
>
> You can remove one pair of parentheses for readability as follows:
>
> #define RelationNeedsWAL(relation)
> \
> + (wal_level != WAL_LEVEL_NONE &&
> \
> (relation)->rd_rel->relpersistence ==
> RELPERSISTENCE_PERMANENT && \
> (XLogIsNeeded() ||
> \
> (relation->rd_createSubid == InvalidSubTransactionId &&
> \
> - relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
> + relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
Done.
> (2)
> /*
> + * Detect if the server previously crashed under wal_level='none' or
> not.
> + */
> + if (ControlFile->wal_level == WAL_LEVEL_NONE &&
> + (ControlFile->state != DB_SHUTDOWNED &&
> ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY))
> + ereport(ERROR,
> + (errmsg("detected an unexpected server
> shutdown when WAL logging was disabled"),
> + errhint("It looks like you need to deploy a
> new cluster from your full backup again.")));
> +
> + /*
> * Check that contents look valid.
> */
> if (!XRecOffIsValid(ControlFile->checkPoint))
>
> I think the above safeguard should be placed right before the following code,
> because it's better to first check control file contents and emit the message
> for the previous shutdown state.
>
> #ifdef XLOG_REPLAY_DELAY
> if (ControlFile->state != DB_SHUTDOWNED)
> pg_usleep(60000000L);
> #endif
Thank you. Perfectly makes sense. Fixed.
> (3)
> @@ -449,6 +449,13 @@ XLogInsert(RmgrId rmid, uint8 info)
> return EndPos;
> }
>
> + /* Issues WAL only for XLOG resources */
> + if (wal_level == WAL_LEVEL_NONE && rmid != RM_XLOG_ID)
> + {
> + XLogResetInsertion();
> + return GetLatestCheckPointLSN();
> + }
>
> It should be correct to use GetXLogInsertRecPtr() instead of
> GetLatestCheckPointLSN(), because what XLogInsert() should return is the
> end position of last WAL record inserted (= start position of next WAL).
Ah, sorry. My patch was not correct.
> Why don't we add transaction completion WAL records? That is, add
> "rmid != RM_XACT_ID" to the if condition. What we really want to eliminate
> for performance is the data modification WAL records. This might allow us
> to insert special checks to prevent PREPARE TRANSACTION and other stuff.
I apologize that you mentioned this point in your past review but I took it wrongly.
I fixed the condition and the comment for it.
> What happens without these checks?
> (4)
> @@ -404,6 +404,10 @@
> pg_logical_emit_message_bytea(PG_FUNCTION_ARGS)
> bytea *data = PG_GETARG_BYTEA_PP(2);
> XLogRecPtr lsn;
>
> + if (wal_level < WAL_LEVEL_REPLICA)
> + ereport(ERROR,
> + errmsg("propagating a message requires
> wal_level \"replica\" or \"logical\""));
> +
> lsn = LogLogicalMessage(prefix, VARDATA_ANY(data),
> VARSIZE_ANY_EXHDR(data),
> transactional);
> PG_RETURN_LSN(lsn);
>
> @@ -192,6 +192,10 @@ replorigin_check_prerequisites(bool check_slots,
> bool recoveryOK)
>
> (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
> errmsg("cannot manipulate replication
> origins during recovery")));
>
> + if (wal_level < WAL_LEVEL_REPLICA)
> + ereport(ERROR,
> + errmsg("creating replication origins requires
> wal_level \"replica\" or \"logical\""));
> +
> }
Those functions doesn't do something meaningful when wal_level <= minimal.
For example, pg_logical_emit_message_bytea calls XLogInsert with RM_LOGICALMSG_ID rmid.
This doesn't generate WAL during wal_level=none,
which makes the usage of the function nonsense.
But, the latest patch I attached removed this part of modification,
because this can be applied to wal_level = minimal also and
I should make the patch focus on its purpose only.
> @@ -625,6 +625,9 @@ standard_ProcessUtility(PlannedStmt *pstmt,
> break;
>
> case TRANS_STMT_PREPARE:
> + if (wal_level ==
> WAL_LEVEL_NONE)
> + ereport(ERROR,
> +
> errmsg("cannot execute PREPARE TRANSACTION when WAL
> logging is disabled"));
Usually, this safeguard is not needed for PREPARE TRANSACTION.
But, when an unexpected crash happens, user needs
to recreate the cluster from the backup and
execute the operations that are executed into the crashed server again
if the user sets wal_level=none.
While 2PC guarantees that after issuing PREPARE TRANSACTION,
the processing or the contents of the transaction becomes *secure*,
setting wal_level=none makes the server never start up again if a database crash occurs.
In other words, this safeguard of the new wal_level damages
the important aspect of PREPARE TRANSACTION's functionality, in my opinion.
I don't think this is what it should be.
Therefore, I don't want users to utilize the PREPARE TRANSACTION still
in order to prevent that user thinks that they can use PREPARE TRANSACTION
safely during wal_level=none and execute it.
Did it make sense ?
Lastly, I fixed the documentation related to the types of generated WAL as well.
Best,
Takamichi Osumi
Attachments:
[application/octet-stream] disable_WAL_logging_v03.patch (14.2K, ../../OSBPR01MB488853A6D77DC783647BE653EDFF0@OSBPR01MB4888.jpnprd01.prod.outlook.com/2-disable_WAL_logging_v03.patch)
download | inline diff:
From fa1a671beb66afbe34a0d1c87115d7b5a4b57073 Mon Sep 17 00:00:00 2001
From: Osumi Takamichi <[email protected]>
Date: Fri, 20 Nov 2020 12:18:22 +0000
Subject: [PATCH v03] new wal_level to disable WAL logging
In order to speed up the performance, especially
for bulk data loading or pg_dumpall, this feature turns off
generation of WAL except for ones associated with transaction and
XLOG resources. This means we gain this speed-up even at the cost of crash recovery.
During the operation of this new wal_level,
an unexpected stoppage or shutdown of the server
makes the whole cluster corrupted and unrecoverable.
Therefore, taking a full backup before and after the operation is a must.
Author: Takamichi Osumi <[email protected]>
Reviewed-by: Tsunakawa Takayuki <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Reviewed-by: Laurenz Albe <[email protected]>
Reviewed-by: Ashutosh Bapat <[email protected]>
Discussion: https://www.postgresql.org/message-id/TYAPR01MB29901EBE5A3ACCE55BA99186FE320%40TYAPR01MB2990.jpnprd01.prod.outlook.com
---
doc/src/sgml/config.sgml | 20 ++++++++++++++++++--
doc/src/sgml/perform.sgml | 13 ++++++++++---
src/backend/access/rmgrdesc/xlogdesc.c | 1 +
src/backend/access/transam/varsup.c | 2 +-
src/backend/access/transam/xlog.c | 13 +++++++++++--
src/backend/access/transam/xloginsert.c | 8 ++++++++
src/backend/postmaster/postmaster.c | 6 +++---
src/backend/tcop/utility.c | 3 +++
src/backend/utils/misc/postgresql.conf.sample | 6 ++++--
src/bin/pg_controldata/pg_controldata.c | 2 ++
src/include/access/xlog.h | 3 ++-
src/include/access/xlogdefs.h | 2 +-
src/include/utils/rel.h | 3 ++-
13 files changed, 66 insertions(+), 16 deletions(-)
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index a632cf9..ada17fe 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -2594,7 +2594,15 @@ include_dir 'conf.d'
data to support WAL archiving and replication, including running
read-only queries on a standby server. <literal>minimal</literal> removes all
logging except the information required to recover from a crash or
- immediate shutdown. Finally,
+ immediate shutdown. <literal>none</literal> generates no WAL
+ except for ones related to transaction or transaction resources such as the end of commit
+ or the indication of checkpoint. This means that the amount of WAL during <literal>none</literal>
+ operation could be much less than that of <literal>minimal</literal> for ordinal operation.
+ Intrinsically, the purpose of <literal>none</literal>
+ is to accelerate data bulk loading at the expense of recovery.
+ Accordingly, note that crash during <literal>none</literal> makes
+ the whole cluster corrupted and unrecoverable. Therefore, never use this mode
+ unless the operation during the mode is repeatable and the cluster is backed up. Finally,
<literal>logical</literal> adds information necessary to support logical
decoding. Each level includes the information logged at all lower
levels. This parameter can only be set at server start.
@@ -2618,6 +2626,13 @@ include_dir 'conf.d'
data from a base backup and the WAL logs, so <literal>replica</literal> or
higher must be used to enable WAL archiving
(<xref linkend="guc-archive-mode"/>) and streaming replication.
+ In the same way, <literal>none</literal> does not create WAL logs in principle.
+ Therefore, this <varname>wal_level</varname> can be used to maximize the speed of data loading.
+ For example, bulk data loading or version upgrade using pg_dumpall.
+ On the other hand, an unexpected crash of the server makes the database cluster
+ inconsistent and never able to restart. For that reason, before utilizing this level,
+ get a full backup of both the cluster itself and the entire operations
+ that are done under the condition that <varname>wal_level</varname> is <literal>none</literal>.
</para>
<para>
In <literal>logical</literal> level, the same information is logged as
@@ -3375,7 +3390,8 @@ include_dir 'conf.d'
changed without leaving archiving mode.
This parameter can only be set at server start.
<varname>archive_mode</varname> cannot be enabled when
- <varname>wal_level</varname> is set to <literal>minimal</literal>.
+ <varname>wal_level</varname> is set to <literal>none</literal> or
+ <literal>minimal</literal>.
</para>
</listitem>
</varlistentry>
diff --git a/doc/src/sgml/perform.sgml b/doc/src/sgml/perform.sgml
index 117a1f7..07d47d4 100644
--- a/doc/src/sgml/perform.sgml
+++ b/doc/src/sgml/perform.sgml
@@ -1741,10 +1741,17 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
new base backup after the load has completed than to process a large
amount of incremental WAL data. To prevent incremental WAL logging
while loading, disable archiving and streaming replication, by setting
- <xref linkend="guc-wal-level"/> to <literal>minimal</literal>,
+ <xref linkend="guc-wal-level"/> to either <literal>none</literal>
+ or <literal>minimal</literal>,
<xref linkend="guc-archive-mode"/> to <literal>off</literal>, and
<xref linkend="guc-max-wal-senders"/> to zero.
- But note that changing these settings requires a server restart.
+ Changing <literal>wal_level</literal> to <literal>none</literal>
+ is extremely performance-oriented feature. Therefore, paying
+ a careful attention that a crash during the data loading causes
+ corruption of the whole cluster is needed. When it happens,
+ the server will not restart again any more and the administrator
+ needs to set up the cluster from the full backup.
+ Also, note that changing these settings requires a server restart.
</para>
<para>
@@ -1810,7 +1817,7 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
If using WAL archiving or streaming replication, consider disabling
them during the restore. To do that, set <varname>archive_mode</varname>
to <literal>off</literal>,
- <varname>wal_level</varname> to <literal>minimal</literal>, and
+ <varname>wal_level</varname> to <literal>minimal</literal> or <literal>none</literal>, and
<varname>max_wal_senders</varname> to zero before loading the dump.
Afterwards, set them back to the right values and take a fresh
base backup.
diff --git a/src/backend/access/rmgrdesc/xlogdesc.c b/src/backend/access/rmgrdesc/xlogdesc.c
index 3200f77..8293b3b 100644
--- a/src/backend/access/rmgrdesc/xlogdesc.c
+++ b/src/backend/access/rmgrdesc/xlogdesc.c
@@ -25,6 +25,7 @@
* GUC support
*/
const struct config_enum_entry wal_level_options[] = {
+ {"none", WAL_LEVEL_NONE, false},
{"minimal", WAL_LEVEL_MINIMAL, false},
{"replica", WAL_LEVEL_REPLICA, false},
{"archive", WAL_LEVEL_REPLICA, true}, /* deprecated */
diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c
index a4944fa..712943a 100644
--- a/src/backend/access/transam/varsup.c
+++ b/src/backend/access/transam/varsup.c
@@ -368,7 +368,7 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid)
* within 3M transactions of data loss. This leaves lots of room for the
* DBA to fool around fixing things in a standalone backend, while not
* being significant compared to total XID space. (VACUUM requires an XID
- * if it truncates at wal_level!=minimal. "VACUUM (ANALYZE)", which a DBA
+ * if it truncates at wal_level<=minimal. "VACUUM (ANALYZE)", which a DBA
* might do by reflex, assigns an XID. Hence, we had better be sure
* there's lots of XIDs left...) Also, at default BLCKSZ, this leaves two
* completely-idle segments. In the event of edge-case bugs involving
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 7d97b96..6a27257 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6254,10 +6254,10 @@ CheckRequiredParameterValues(void)
* For archive recovery, the WAL must be generated with at least 'replica'
* wal_level.
*/
- if (ArchiveRecoveryRequested && ControlFile->wal_level == WAL_LEVEL_MINIMAL)
+ if (ArchiveRecoveryRequested && ControlFile->wal_level <= WAL_LEVEL_MINIMAL)
{
ereport(WARNING,
- (errmsg("WAL was generated with wal_level=minimal, data may be missing"),
+ (errmsg("WAL was generated with wal_level<=minimal, data may be missing"),
errhint("This happens if you temporarily set wal_level=minimal without taking a new base backup.")));
}
@@ -6386,6 +6386,15 @@ StartupXLOG(void)
(errmsg("control file contains invalid database cluster state")));
}
+ /*
+ * Detect if the server previously crashed under wal_level='none' or not.
+ */
+ if (ControlFile->wal_level == WAL_LEVEL_NONE &&
+ (ControlFile->state != DB_SHUTDOWNED && ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY))
+ ereport(ERROR,
+ (errmsg("detected an unexpected server shutdown when WAL logging was disabled"),
+ errhint("It looks like you need to deploy a new cluster from your full backup again.")));
+
/* This is just to allow attaching to startup process with a debugger */
#ifdef XLOG_REPLAY_DELAY
if (ControlFile->state != DB_SHUTDOWNED)
diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c
index 1f0e4e0..a44fb70 100644
--- a/src/backend/access/transam/xloginsert.c
+++ b/src/backend/access/transam/xloginsert.c
@@ -449,6 +449,14 @@ XLogInsert(RmgrId rmid, uint8 info)
return EndPos;
}
+ /* Issues WAL related to XLOG resources and transactions only */
+ if (wal_level == WAL_LEVEL_NONE &&
+ rmid != RM_XLOG_ID && rmid != RM_XACT_ID)
+ {
+ XLogResetInsertion();
+ return GetXLogInsertRecPtr();
+ }
+
do
{
XLogRecPtr RedoRecPtr;
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index b7799ed..27e4475 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -903,10 +903,10 @@ PostmasterMain(int argc, char *argv[])
ReservedBackends, MaxConnections);
ExitPostmaster(1);
}
- if (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level == WAL_LEVEL_MINIMAL)
+ if (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level <= WAL_LEVEL_MINIMAL)
ereport(ERROR,
- (errmsg("WAL archival cannot be enabled when wal_level is \"minimal\"")));
- if (max_wal_senders > 0 && wal_level == WAL_LEVEL_MINIMAL)
+ (errmsg("WAL archival cannot be enabled when wal_level is \"none\" or \"\"minimal")));
+ if (max_wal_senders > 0 && wal_level <= WAL_LEVEL_MINIMAL)
ereport(ERROR,
(errmsg("WAL streaming (max_wal_senders > 0) requires wal_level \"replica\" or \"logical\"")));
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index f398027..0f7597b 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -625,6 +625,9 @@ standard_ProcessUtility(PlannedStmt *pstmt,
break;
case TRANS_STMT_PREPARE:
+ if (wal_level == WAL_LEVEL_NONE)
+ ereport(ERROR,
+ errmsg("cannot execute PREPARE TRANSACTION when WAL logging is disabled"));
if (!PrepareTransactionBlock(stmt->gid))
{
/* report unsuccessful commit in qc */
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 9cb571f..9bf89e5 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -196,8 +196,10 @@
# - Settings -
-#wal_level = replica # minimal, replica, or logical
- # (change requires restart)
+#wal_level = replica # none, minimal, replica, or logical
+ # (change requires restart.
+ # choosing the none wal_level
+ # can cause unrecoverable data corruption)
#fsync = on # flush data to disk for crash safety
# (turning this off can cause
# unrecoverable data corruption)
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 3e00ac0..90ec0dc 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -74,6 +74,8 @@ wal_level_str(WalLevel wal_level)
{
switch (wal_level)
{
+ case WAL_LEVEL_NONE:
+ return "none";
case WAL_LEVEL_MINIMAL:
return "minimal";
case WAL_LEVEL_REPLICA:
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 221af87..75f4404 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -161,7 +161,8 @@ extern int XLogArchiveMode;
/* WAL levels */
typedef enum WalLevel
{
- WAL_LEVEL_MINIMAL = 0,
+ WAL_LEVEL_NONE = 0,
+ WAL_LEVEL_MINIMAL,
WAL_LEVEL_REPLICA,
WAL_LEVEL_LOGICAL
} WalLevel;
diff --git a/src/include/access/xlogdefs.h b/src/include/access/xlogdefs.h
index e1f5812..197ad06 100644
--- a/src/include/access/xlogdefs.h
+++ b/src/include/access/xlogdefs.h
@@ -59,7 +59,7 @@ typedef uint16 RepOriginId;
/*
* Because O_DIRECT bypasses the kernel buffers, and because we never
- * read those buffers except during crash recovery or if wal_level != minimal,
+ * read those buffers except during crash recovery or if wal_level <= minimal,
* it is a win to use it in all cases where we sync on each write(). We could
* allow O_DIRECT with fsync(), but it is unclear if fsync() could process
* writes not buffered in the kernel. Also, O_DIRECT is never enough to force
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index c5ffea4..201afca 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -561,7 +561,8 @@ typedef struct ViewOptions
* RelFileNode" in src/backend/access/transam/README.
*/
#define RelationNeedsWAL(relation) \
- ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \
+ (wal_level != WAL_LEVEL_NONE && \
+ (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \
(XLogIsNeeded() || \
(relation->rd_createSubid == InvalidSubTransactionId && \
relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
--
1.8.3.1
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-23 03:17 ` [email protected] <[email protected]>
2020-11-24 02:18 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-11-23 03:17 UTC (permalink / raw)
To: [email protected] <[email protected]>; +Cc: 'Fujii Masao' <[email protected]>; Laurenz Albe <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
From: Osumi, Takamichi/大墨 昂道 <[email protected]>
> > case TRANS_STMT_PREPARE:
> > + if (wal_level ==
> > WAL_LEVEL_NONE)
> > + ereport(ERROR,
> > +
> > errmsg("cannot execute PREPARE TRANSACTION when WAL logging
> is
> > disabled"));
> Usually, this safeguard is not needed for PREPARE TRANSACTION.
> But, when an unexpected crash happens, user needs to recreate the cluster
> from the backup and execute the operations that are executed into the crashed
> server again if the user sets wal_level=none.
>
> While 2PC guarantees that after issuing PREPARE TRANSACTION, the
> processing or the contents of the transaction becomes *secure*, setting
> wal_level=none makes the server never start up again if a database crash
> occurs.
> In other words, this safeguard of the new wal_level damages the important
> aspect of PREPARE TRANSACTION's functionality, in my opinion.
>
> I don't think this is what it should be.
>
> Therefore, I don't want users to utilize the PREPARE TRANSACTION still in
> order to prevent that user thinks that they can use PREPARE TRANSACTION
> safely during wal_level=none and execute it.
> Did it make sense ?
PREPARE TRANSACTION is the same as COMMIT in that it persists transaction updates. A crash during wal_level = none loses both of them. So, I don't think PREPARE TRANSACTION needs special treatment.
Does PREPARE TRANSACTION complete successfully? I remember Fujii-san said it PANICed if --enable-asserts is used in configure.
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-23 03:17 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-24 02:18 ` [email protected] <[email protected]>
2020-11-27 06:07 ` Re: Disable WAL logging to speed up data loading Masahiko Sawada <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-11-24 02:18 UTC (permalink / raw)
To: [email protected] <[email protected]>; +Cc: 'Fujii Masao' <[email protected]>; Laurenz Albe <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Hi
On Monday, Nov 23, 2020 12:17 PM Tsunakawa, Takayuki <[email protected]> wrote:
> PREPARE TRANSACTION is the same as COMMIT in that it persists
> transaction updates. A crash during wal_level = none loses both of them.
> So, I don't think PREPARE TRANSACTION needs special treatment.
Yeah, I got it. That makes sense.
Attached is the one I removed the special treatment.
> Does PREPARE TRANSACTION complete successfully? I remember
> Fujii-san said it PANICed if --enable-asserts is used in configure.
Yes. That assertion failure Fujii-San reported in the past
was solved by having rmid != RM_XACT_ID in XLogInsert()
to add WAL generation for transaction completes.
That I missed the condition was the cause but fine now.
Plus, PREPARE TRANSACTION and COMMIT PREPARED
works successfully at present when no happening occurs.
Best,
Takamichi Osumi
Attachments:
[application/octet-stream] disable_WAL_logging_v04.patch (13.7K, ../../OSBPR01MB48883072D368C336F640A063EDFB0@OSBPR01MB4888.jpnprd01.prod.outlook.com/2-disable_WAL_logging_v04.patch)
download | inline diff:
From 4d7f4765470fe0617024e9b9c2067d353e0a0c60 Mon Sep 17 00:00:00 2001
From: Osumi Takamichi <[email protected]>
Date: Tue, 24 Nov 2020 01:27:31 +0000
Subject: [PATCH v04] new wal_level to disable WAL logging
In order to speed up the performance, especially
for bulk data loading or pg_dumpall, this feature turns off
generation of WAL except for ones associated with transaction and
XLOG resources. This means we gain this speed-up even at the cost of crash recovery.
During the operation of this new wal_level,
an unexpected stoppage or shutdown of the server
makes the whole cluster corrupted and unrecoverable.
Therefore, taking a full backup before and after the operation is a must.
Author: Takamichi Osumi <[email protected]>
Reviewed-by: Tsunakawa Takayuki <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Reviewed-by: Laurenz Albe <[email protected]>
Reviewed-by: Ashutosh Bapat <[email protected]>
Discussion: https://www.postgresql.org/message-id/TYAPR01MB29901EBE5A3ACCE55BA99186FE320%40TYAPR01MB2990.jpnprd01.prod.outlook.com
---
doc/src/sgml/config.sgml | 20 ++++++++++++++++++--
doc/src/sgml/perform.sgml | 13 ++++++++++---
src/backend/access/rmgrdesc/xlogdesc.c | 1 +
src/backend/access/transam/varsup.c | 2 +-
src/backend/access/transam/xlog.c | 13 +++++++++++--
src/backend/access/transam/xloginsert.c | 8 ++++++++
src/backend/postmaster/postmaster.c | 6 +++---
src/backend/utils/misc/postgresql.conf.sample | 6 ++++--
src/bin/pg_controldata/pg_controldata.c | 2 ++
src/include/access/xlog.h | 3 ++-
src/include/access/xlogdefs.h | 2 +-
src/include/utils/rel.h | 3 ++-
12 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index f043433..97c1a05 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -2591,7 +2591,15 @@ include_dir 'conf.d'
data to support WAL archiving and replication, including running
read-only queries on a standby server. <literal>minimal</literal> removes all
logging except the information required to recover from a crash or
- immediate shutdown. Finally,
+ immediate shutdown. <literal>none</literal> generates no WAL
+ except for ones related to transaction or transaction resources such as the end of commit
+ or the indication of checkpoint. This means that the amount of WAL during <literal>none</literal>
+ operation could be much less than that of <literal>minimal</literal> for ordinal operation.
+ Intrinsically, the purpose of <literal>none</literal>
+ is to accelerate data bulk loading at the expense of recovery.
+ Accordingly, note that crash during <literal>none</literal> makes
+ the whole cluster corrupted and unrecoverable. Therefore, never use this mode
+ unless the operation during the mode is repeatable and the cluster is backed up. Finally,
<literal>logical</literal> adds information necessary to support logical
decoding. Each level includes the information logged at all lower
levels. This parameter can only be set at server start.
@@ -2615,6 +2623,13 @@ include_dir 'conf.d'
data from a base backup and the WAL logs, so <literal>replica</literal> or
higher must be used to enable WAL archiving
(<xref linkend="guc-archive-mode"/>) and streaming replication.
+ In the same way, <literal>none</literal> does not create WAL logs in principle.
+ Therefore, this <varname>wal_level</varname> can be used to maximize the speed of data loading.
+ For example, bulk data loading or version upgrade using pg_dumpall.
+ On the other hand, an unexpected crash of the server makes the database cluster
+ inconsistent and never able to restart. For that reason, before utilizing this level,
+ get a full backup of both the cluster itself and the entire operations
+ that are done under the condition that <varname>wal_level</varname> is <literal>none</literal>.
</para>
<para>
In <literal>logical</literal> level, the same information is logged as
@@ -3372,7 +3387,8 @@ include_dir 'conf.d'
changed without leaving archiving mode.
This parameter can only be set at server start.
<varname>archive_mode</varname> cannot be enabled when
- <varname>wal_level</varname> is set to <literal>minimal</literal>.
+ <varname>wal_level</varname> is set to <literal>none</literal> or
+ <literal>minimal</literal>.
</para>
</listitem>
</varlistentry>
diff --git a/doc/src/sgml/perform.sgml b/doc/src/sgml/perform.sgml
index 117a1f7..07d47d4 100644
--- a/doc/src/sgml/perform.sgml
+++ b/doc/src/sgml/perform.sgml
@@ -1741,10 +1741,17 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
new base backup after the load has completed than to process a large
amount of incremental WAL data. To prevent incremental WAL logging
while loading, disable archiving and streaming replication, by setting
- <xref linkend="guc-wal-level"/> to <literal>minimal</literal>,
+ <xref linkend="guc-wal-level"/> to either <literal>none</literal>
+ or <literal>minimal</literal>,
<xref linkend="guc-archive-mode"/> to <literal>off</literal>, and
<xref linkend="guc-max-wal-senders"/> to zero.
- But note that changing these settings requires a server restart.
+ Changing <literal>wal_level</literal> to <literal>none</literal>
+ is extremely performance-oriented feature. Therefore, paying
+ a careful attention that a crash during the data loading causes
+ corruption of the whole cluster is needed. When it happens,
+ the server will not restart again any more and the administrator
+ needs to set up the cluster from the full backup.
+ Also, note that changing these settings requires a server restart.
</para>
<para>
@@ -1810,7 +1817,7 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
If using WAL archiving or streaming replication, consider disabling
them during the restore. To do that, set <varname>archive_mode</varname>
to <literal>off</literal>,
- <varname>wal_level</varname> to <literal>minimal</literal>, and
+ <varname>wal_level</varname> to <literal>minimal</literal> or <literal>none</literal>, and
<varname>max_wal_senders</varname> to zero before loading the dump.
Afterwards, set them back to the right values and take a fresh
base backup.
diff --git a/src/backend/access/rmgrdesc/xlogdesc.c b/src/backend/access/rmgrdesc/xlogdesc.c
index 3200f77..8293b3b 100644
--- a/src/backend/access/rmgrdesc/xlogdesc.c
+++ b/src/backend/access/rmgrdesc/xlogdesc.c
@@ -25,6 +25,7 @@
* GUC support
*/
const struct config_enum_entry wal_level_options[] = {
+ {"none", WAL_LEVEL_NONE, false},
{"minimal", WAL_LEVEL_MINIMAL, false},
{"replica", WAL_LEVEL_REPLICA, false},
{"archive", WAL_LEVEL_REPLICA, true}, /* deprecated */
diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c
index a4944fa..712943a 100644
--- a/src/backend/access/transam/varsup.c
+++ b/src/backend/access/transam/varsup.c
@@ -368,7 +368,7 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid)
* within 3M transactions of data loss. This leaves lots of room for the
* DBA to fool around fixing things in a standalone backend, while not
* being significant compared to total XID space. (VACUUM requires an XID
- * if it truncates at wal_level!=minimal. "VACUUM (ANALYZE)", which a DBA
+ * if it truncates at wal_level<=minimal. "VACUUM (ANALYZE)", which a DBA
* might do by reflex, assigns an XID. Hence, we had better be sure
* there's lots of XIDs left...) Also, at default BLCKSZ, this leaves two
* completely-idle segments. In the event of edge-case bugs involving
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index aa63f37..887767b 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6254,10 +6254,10 @@ CheckRequiredParameterValues(void)
* For archive recovery, the WAL must be generated with at least 'replica'
* wal_level.
*/
- if (ArchiveRecoveryRequested && ControlFile->wal_level == WAL_LEVEL_MINIMAL)
+ if (ArchiveRecoveryRequested && ControlFile->wal_level <= WAL_LEVEL_MINIMAL)
{
ereport(WARNING,
- (errmsg("WAL was generated with wal_level=minimal, data may be missing"),
+ (errmsg("WAL was generated with wal_level<=minimal, data may be missing"),
errhint("This happens if you temporarily set wal_level=minimal without taking a new base backup.")));
}
@@ -6386,6 +6386,15 @@ StartupXLOG(void)
(errmsg("control file contains invalid database cluster state")));
}
+ /*
+ * Detect if the server previously crashed under wal_level='none' or not.
+ */
+ if (ControlFile->wal_level == WAL_LEVEL_NONE &&
+ (ControlFile->state != DB_SHUTDOWNED && ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY))
+ ereport(ERROR,
+ (errmsg("detected an unexpected server shutdown when WAL logging was disabled"),
+ errhint("It looks like you need to deploy a new cluster from your full backup again.")));
+
/* This is just to allow attaching to startup process with a debugger */
#ifdef XLOG_REPLAY_DELAY
if (ControlFile->state != DB_SHUTDOWNED)
diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c
index 1f0e4e0..a44fb70 100644
--- a/src/backend/access/transam/xloginsert.c
+++ b/src/backend/access/transam/xloginsert.c
@@ -449,6 +449,14 @@ XLogInsert(RmgrId rmid, uint8 info)
return EndPos;
}
+ /* Issues WAL related to XLOG resources and transactions only */
+ if (wal_level == WAL_LEVEL_NONE &&
+ rmid != RM_XLOG_ID && rmid != RM_XACT_ID)
+ {
+ XLogResetInsertion();
+ return GetXLogInsertRecPtr();
+ }
+
do
{
XLogRecPtr RedoRecPtr;
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index b7799ed..27e4475 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -903,10 +903,10 @@ PostmasterMain(int argc, char *argv[])
ReservedBackends, MaxConnections);
ExitPostmaster(1);
}
- if (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level == WAL_LEVEL_MINIMAL)
+ if (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level <= WAL_LEVEL_MINIMAL)
ereport(ERROR,
- (errmsg("WAL archival cannot be enabled when wal_level is \"minimal\"")));
- if (max_wal_senders > 0 && wal_level == WAL_LEVEL_MINIMAL)
+ (errmsg("WAL archival cannot be enabled when wal_level is \"none\" or \"\"minimal")));
+ if (max_wal_senders > 0 && wal_level <= WAL_LEVEL_MINIMAL)
ereport(ERROR,
(errmsg("WAL streaming (max_wal_senders > 0) requires wal_level \"replica\" or \"logical\"")));
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 9cb571f..9bf89e5 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -196,8 +196,10 @@
# - Settings -
-#wal_level = replica # minimal, replica, or logical
- # (change requires restart)
+#wal_level = replica # none, minimal, replica, or logical
+ # (change requires restart.
+ # choosing the none wal_level
+ # can cause unrecoverable data corruption)
#fsync = on # flush data to disk for crash safety
# (turning this off can cause
# unrecoverable data corruption)
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 3e00ac0..90ec0dc 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -74,6 +74,8 @@ wal_level_str(WalLevel wal_level)
{
switch (wal_level)
{
+ case WAL_LEVEL_NONE:
+ return "none";
case WAL_LEVEL_MINIMAL:
return "minimal";
case WAL_LEVEL_REPLICA:
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 221af87..75f4404 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -161,7 +161,8 @@ extern int XLogArchiveMode;
/* WAL levels */
typedef enum WalLevel
{
- WAL_LEVEL_MINIMAL = 0,
+ WAL_LEVEL_NONE = 0,
+ WAL_LEVEL_MINIMAL,
WAL_LEVEL_REPLICA,
WAL_LEVEL_LOGICAL
} WalLevel;
diff --git a/src/include/access/xlogdefs.h b/src/include/access/xlogdefs.h
index e1f5812..197ad06 100644
--- a/src/include/access/xlogdefs.h
+++ b/src/include/access/xlogdefs.h
@@ -59,7 +59,7 @@ typedef uint16 RepOriginId;
/*
* Because O_DIRECT bypasses the kernel buffers, and because we never
- * read those buffers except during crash recovery or if wal_level != minimal,
+ * read those buffers except during crash recovery or if wal_level <= minimal,
* it is a win to use it in all cases where we sync on each write(). We could
* allow O_DIRECT with fsync(), but it is unclear if fsync() could process
* writes not buffered in the kernel. Also, O_DIRECT is never enough to force
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index c5ffea4..201afca 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -561,7 +561,8 @@ typedef struct ViewOptions
* RelFileNode" in src/backend/access/transam/README.
*/
#define RelationNeedsWAL(relation) \
- ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \
+ (wal_level != WAL_LEVEL_NONE && \
+ (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \
(XLogIsNeeded() || \
(relation->rd_createSubid == InvalidSubTransactionId && \
relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
--
1.8.3.1
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-23 03:17 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-24 02:18 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-27 06:07 ` Masahiko Sawada <[email protected]>
2020-11-27 06:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-11-27 07:01 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-27 09:23 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
0 siblings, 3 replies; 392+ messages in thread
From: Masahiko Sawada @ 2020-11-27 06:07 UTC (permalink / raw)
To: [email protected] <[email protected]>; +Cc: [email protected] <[email protected]>; Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
On Tue, Nov 24, 2020 at 11:19 AM [email protected]
<[email protected]> wrote:
>
> Hi
>
> On Monday, Nov 23, 2020 12:17 PM Tsunakawa, Takayuki <[email protected]> wrote:
> > PREPARE TRANSACTION is the same as COMMIT in that it persists
> > transaction updates. A crash during wal_level = none loses both of them.
> > So, I don't think PREPARE TRANSACTION needs special treatment.
> Yeah, I got it. That makes sense.
> Attached is the one I removed the special treatment.
>
>
> > Does PREPARE TRANSACTION complete successfully? I remember
> > Fujii-san said it PANICed if --enable-asserts is used in configure.
> Yes. That assertion failure Fujii-San reported in the past
> was solved by having rmid != RM_XACT_ID in XLogInsert()
> to add WAL generation for transaction completes.
> That I missed the condition was the cause but fine now.
>
> Plus, PREPARE TRANSACTION and COMMIT PREPARED
> works successfully at present when no happening occurs.
>
Thank you for updating the patch.
- (errmsg("WAL was generated with wal_level=minimal,
data may be missing"),
+ (errmsg("WAL was generated with wal_level<=minimal,
data may be missing"),
errhint("This happens if you temporarily set
wal_level=minimal without taking a new base backup.")));
'wal_level=minimal' in errhint also needs to be changed to 'wal_level<=minimal'?
While testing the patch on some workload, I realized that
XLOG_FPI_FOR_HINT record could still be emitted even when wal_level =
none. IIUC that WAL record is not necessary during wal_level = none
since the server cannot be the primary server and the server crash
ends up requiring to restore the whole database.
Regards,
--
Masahiko Sawada
EnterpriseDB: https://www.enterprisedb.com/
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-23 03:17 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-24 02:18 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-27 06:07 ` Re: Disable WAL logging to speed up data loading Masahiko Sawada <[email protected]>
@ 2020-11-27 06:38 ` Kyotaro Horiguchi <[email protected]>
2 siblings, 0 replies; 392+ messages in thread
From: Kyotaro Horiguchi @ 2020-11-27 06:38 UTC (permalink / raw)
To: [email protected]; +Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
At Fri, 27 Nov 2020 15:07:34 +0900, Masahiko Sawada <[email protected]> wrote in
> On Tue, Nov 24, 2020 at 11:19 AM [email protected]
> <[email protected]> wrote:
> >
> > Hi
> >
> > On Monday, Nov 23, 2020 12:17 PM Tsunakawa, Takayuki <[email protected]> wrote:
> > > PREPARE TRANSACTION is the same as COMMIT in that it persists
> > > transaction updates. A crash during wal_level = none loses both of them.
> > > So, I don't think PREPARE TRANSACTION needs special treatment.
> > Yeah, I got it. That makes sense.
> > Attached is the one I removed the special treatment.
> >
> >
> > > Does PREPARE TRANSACTION complete successfully? I remember
> > > Fujii-san said it PANICed if --enable-asserts is used in configure.
> > Yes. That assertion failure Fujii-San reported in the past
> > was solved by having rmid != RM_XACT_ID in XLogInsert()
> > to add WAL generation for transaction completes.
> > That I missed the condition was the cause but fine now.
> >
> > Plus, PREPARE TRANSACTION and COMMIT PREPARED
> > works successfully at present when no happening occurs.
> >
>
> Thank you for updating the patch.
>
> - (errmsg("WAL was generated with wal_level=minimal,
> data may be missing"),
> + (errmsg("WAL was generated with wal_level<=minimal,
> data may be missing"),
> errhint("This happens if you temporarily set
> wal_level=minimal without taking a new base backup.")));
>
> 'wal_level=minimal' in errhint also needs to be changed to 'wal_level<=minimal'?
>
> While testing the patch on some workload, I realized that
> XLOG_FPI_FOR_HINT record could still be emitted even when wal_level =
> none. IIUC that WAL record is not necessary during wal_level = none
> since the server cannot be the primary server and the server crash
> ends up requiring to restore the whole database.
It seems to be on purpose.
@@ -449,6 +449,14 @@ XLogInsert(RmgrId rmid, uint8 info)
return EndPos;
}
+ /* Issues WAL related to XLOG resources and transactions only */
+ if (wal_level == WAL_LEVEL_NONE &&
+ rmid != RM_XLOG_ID && rmid != RM_XACT_ID)
+ {
+ XLogResetInsertion();
+ return GetXLogInsertRecPtr();
What is the reason for those kinds of records to be emitted?
I think we must emit at least the shutdown checkpoint record, which
has redo-LSN that points to the record itself. I'm not sure what
other kinds of records are needed.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-23 03:17 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-24 02:18 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-27 06:07 ` Re: Disable WAL logging to speed up data loading Masahiko Sawada <[email protected]>
@ 2020-11-27 07:01 ` [email protected] <[email protected]>
2020-11-27 08:35 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-11-27 09:33 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2 siblings, 2 replies; 392+ messages in thread
From: [email protected] @ 2020-11-27 07:01 UTC (permalink / raw)
To: [email protected] <[email protected]>; 'Masahiko Sawada' <[email protected]>; +Cc: Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
From: Masahiko Sawada <[email protected]>
> While testing the patch on some workload, I realized that
> XLOG_FPI_FOR_HINT record could still be emitted even when wal_level =
> none. IIUC that WAL record is not necessary during wal_level = none
> since the server cannot be the primary server and the server crash
> ends up requiring to restore the whole database.
Nice catch! XLOG_FPI_FOR_HINT and XLOG_FPI should be eliminated, otherwise large amount of WAL may be written. (It seems that other RMIDs than RM_XLOG_ID and RM_XACT_ID do not have to be written.)
I'm afraid "none" doesn't represent the behavior because RM_XLOG_ID and RM_XACT_ID WAL records, except for XLOG_FPI_*, are emitted. What's the good name? IIUC, "minimal" is named after the fact that the minimal amount of WAL necessary for crash recovery is generated. "norecovery" or "unrecoverable"?
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-23 03:17 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-24 02:18 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-27 06:07 ` Re: Disable WAL logging to speed up data loading Masahiko Sawada <[email protected]>
2020-11-27 07:01 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-27 08:35 ` Kyotaro Horiguchi <[email protected]>
2020-11-27 13:34 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: Kyotaro Horiguchi @ 2020-11-27 08:35 UTC (permalink / raw)
To: [email protected]; +Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
At Fri, 27 Nov 2020 07:01:16 +0000, "[email protected]" <[email protected]> wrote in
> From: Masahiko Sawada <[email protected]>
> > While testing the patch on some workload, I realized that
> > XLOG_FPI_FOR_HINT record could still be emitted even when wal_level =
> > none. IIUC that WAL record is not necessary during wal_level = none
> > since the server cannot be the primary server and the server crash
> > ends up requiring to restore the whole database.
>
> Nice catch! XLOG_FPI_FOR_HINT and XLOG_FPI should be eliminated, otherwise large amount of WAL may be written. (It seems that other RMIDs than RM_XLOG_ID and RM_XACT_ID do not have to be written.)
>
> I'm afraid "none" doesn't represent the behavior because RM_XLOG_ID and RM_XACT_ID WAL records, except for XLOG_FPI_*, are emitted. What's the good name? IIUC, "minimal" is named after the fact that the minimal amount of WAL necessary for crash recovery is generated. "norecovery" or "unrecoverable"?
I haven't seen a criteria of whether a record is emitted or not for
wal_leve=none.
We're emitting only redo logs. So I think theoretically we don't need
anything other than the shutdown checkpoint record because we don't
perform recovery and checkpoint record is required at startup.
RM_XLOG_ID:
XLOG_FPI_FOR_HINT - not needed?
XLOG_FPI - not needed?
XLOG_CHECKPOINT_SHUTDOWN - must have
So how about the followings?
XLOG_CHECKPOINT_ONLINE
XLOG_NOOP
XLOG_NEXTOID
XLOG_SWITCH
XLOG_BACKUP_END
XLOG_PARAMETER_CHANGE
XLOG_RESTORE_POINT
XLOG_FPW_CHANGE
XLOG_END_OF_RECOVERY
RM_XACT_ID:
XLOG_XACT_COMMIT
XLOG_XACT_PREPARE
XLOG_XACT_ABORT
XLOG_XACT_COMMIT_PREPARED
XLOG_XACT_ABORT_PREPARED
XLOG_XACT_ASSIGNMENT
XLOG_XACT_INVALIDATIONS
Do we need all of these?
And, currenly what decides whether to emit a wal record according to
wal_level is the caller of XLogInsert. So doing this at
XLogInsert-level means that we bring the criteria of the necessity of
wal-record into xlog layer only for wal_level=none. I'm not sure it is
the right direction.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-23 03:17 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-24 02:18 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-27 06:07 ` Re: Disable WAL logging to speed up data loading Masahiko Sawada <[email protected]>
2020-11-27 07:01 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-27 08:35 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
@ 2020-11-27 13:34 ` [email protected] <[email protected]>
2020-11-30 05:07 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-11-27 13:34 UTC (permalink / raw)
To: 'Kyotaro Horiguchi' <[email protected]>; [email protected] <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Thank you, Horiguchi-San
> I haven't seen a criteria of whether a record is emitted or not for
> wal_leve=none.
>
> We're emitting only redo logs. So I think theoretically we don't need anything
> other than the shutdown checkpoint record because we don't perform
> recovery and checkpoint record is required at startup.
>
> RM_XLOG_ID:
> XLOG_FPI_FOR_HINT - not needed?
> XLOG_FPI - not needed?
>
> XLOG_CHECKPOINT_SHUTDOWN - must have
>
> So how about the followings?
> XLOG_CHECKPOINT_ONLINE
> XLOG_NOOP
> XLOG_NEXTOID
> XLOG_SWITCH
> XLOG_BACKUP_END
> XLOG_PARAMETER_CHANGE
> XLOG_RESTORE_POINT
> XLOG_FPW_CHANGE
> XLOG_END_OF_RECOVERY
>
>
> RM_XACT_ID:
> XLOG_XACT_COMMIT
> XLOG_XACT_PREPARE
> XLOG_XACT_ABORT
> XLOG_XACT_COMMIT_PREPARED
> XLOG_XACT_ABORT_PREPARED
> XLOG_XACT_ASSIGNMENT
> XLOG_XACT_INVALIDATIONS
>
> Do we need all of these?
No. Strictly speaking, you are right.
We still have types of WAL that are not necessarily needed.
For example, XLOG_END_OF_RECOVERY is not useful
because wal_level=none doesn't recover from any accidents.
Or, XLOG_CHECKPOINT_ONLINE is used when we execute CHECKPOINT
not for shutting down. Thus we could eliminate more.
> And, currenly what decides whether to emit a wal record according to
> wal_level is the caller of XLogInsert.
Yes.
> So doing this at XLogInsert-level means
> that we bring the criteria of the necessity of wal-record into xlog layer only for
> wal_level=none. I'm not sure it is the right direction.
I'm sorry. I didn't understand what "doing this" and "xlog layer" meant.
Did you mean that fixing the caller side of XLogInsert (e.g. CreateCheckPoint)
is not the right direction ? Or, fixing the function of XLogInsert is not the right direction ?
> At Fri, 27 Nov 2020 07:01:16 +0000, "[email protected]"
> <[email protected]> wrote in
> > I'm afraid "none" doesn't represent the behavior because RM_XLOG_ID and
> RM_XACT_ID WAL records, except for XLOG_FPI_*, are emitted. What's the
> good name? IIUC, "minimal" is named after the fact that the minimal
> amount of WAL necessary for crash recovery is generated. "norecovery" or
> "unrecoverable"?
Lastly, I found another name which expresses the essential characteristic of this wal_level.
How about the name of wal_level="crash_unsafe" ?
What did you think ?
Best,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-23 03:17 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-24 02:18 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-27 06:07 ` Re: Disable WAL logging to speed up data loading Masahiko Sawada <[email protected]>
2020-11-27 07:01 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-27 08:35 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-11-27 13:34 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-30 05:07 ` Kyotaro Horiguchi <[email protected]>
2020-11-30 06:45 ` Re: Disable WAL logging to speed up data loading Masahiko Sawada <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: Kyotaro Horiguchi @ 2020-11-30 05:07 UTC (permalink / raw)
To: [email protected]; +Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
At Fri, 27 Nov 2020 13:34:49 +0000, "[email protected]" <[email protected]> wrote in
> Thank you, Horiguchi-San
>
> > I haven't seen a criteria of whether a record is emitted or not for
> > wal_leve=none.
> >
> > We're emitting only redo logs. So I think theoretically we don't need anything
> > other than the shutdown checkpoint record because we don't perform
> > recovery and checkpoint record is required at startup.
> >
> > RM_XLOG_ID:
> > XLOG_FPI_FOR_HINT - not needed?
> > XLOG_FPI - not needed?
> >
> > XLOG_CHECKPOINT_SHUTDOWN - must have
> >
> > So how about the followings?
> > XLOG_CHECKPOINT_ONLINE
> > XLOG_NOOP
> > XLOG_NEXTOID
> > XLOG_SWITCH
> > XLOG_BACKUP_END
> > XLOG_PARAMETER_CHANGE
> > XLOG_RESTORE_POINT
> > XLOG_FPW_CHANGE
> > XLOG_END_OF_RECOVERY
> >
> >
> > RM_XACT_ID:
> > XLOG_XACT_COMMIT
> > XLOG_XACT_PREPARE
> > XLOG_XACT_ABORT
> > XLOG_XACT_COMMIT_PREPARED
> > XLOG_XACT_ABORT_PREPARED
> > XLOG_XACT_ASSIGNMENT
> > XLOG_XACT_INVALIDATIONS
> >
> > Do we need all of these?
> No. Strictly speaking, you are right.
> We still have types of WAL that are not necessarily needed.
> For example, XLOG_END_OF_RECOVERY is not useful
> because wal_level=none doesn't recover from any accidents.
> Or, XLOG_CHECKPOINT_ONLINE is used when we execute CHECKPOINT
> not for shutting down. Thus we could eliminate more.
Yeah, although it's enough only to restrict non-harmful records
practically, if we find that only a few kinds of records are needed,
maybe it's cleaner to allow only required record type(s).
> > And, currenly what decides whether to emit a wal record according to
> > wal_level is the caller of XLogInsert.
> Yes.
>
> > So doing this at XLogInsert-level means
> > that we bring the criteria of the necessity of wal-record into xlog layer only for
> > wal_level=none. I'm not sure it is the right direction.
> I'm sorry. I didn't understand what "doing this" and "xlog layer" meant.
"doing this" meant filtering record types.
> Did you mean that fixing the caller side of XLogInsert (e.g. CreateCheckPoint)
> is not the right direction ? Or, fixing the function of XLogInsert is not the right direction ?
Maybe it's right that if we can filter-out records looking only rmid,
since the xlog facility doesn't need to know about record types of a
resource manager. But if we need to finer-grained control on the
record types, I'm afraid that that's wrong. However, if we need only
the XLOG_CHECKPOINT_SHUTDOWN record, it might be better to let
XLogInsert filter records rather than inserting that filtering code to
all the caller sites.
> > At Fri, 27 Nov 2020 07:01:16 +0000, "[email protected]"
> > <[email protected]> wrote in
> > > I'm afraid "none" doesn't represent the behavior because RM_XLOG_ID and
> > RM_XACT_ID WAL records, except for XLOG_FPI_*, are emitted. What's the
> > good name? IIUC, "minimal" is named after the fact that the minimal
> > amount of WAL necessary for crash recovery is generated. "norecovery" or
> > "unrecoverable"?
> Lastly, I found another name which expresses the essential characteristic of this wal_level.
> How about the name of wal_level="crash_unsafe" ?
> What did you think ?
I don't dislike "none" since it seems to me practically "none". It
seems rather correct if we actually need only the shutdown checkpoint
record.
"unrecoverable" is apparently misleading. "crash_unsafe" is precise
but seems somewhat alien being among "logical", "replica" and
"minimal".
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-23 03:17 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-24 02:18 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-27 06:07 ` Re: Disable WAL logging to speed up data loading Masahiko Sawada <[email protected]>
2020-11-27 07:01 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-27 08:35 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-11-27 13:34 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-30 05:07 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
@ 2020-11-30 06:45 ` Masahiko Sawada <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Masahiko Sawada @ 2020-11-30 06:45 UTC (permalink / raw)
To: Kyotaro Horiguchi <[email protected]>; +Cc: [email protected]; tsunakawa.takay <[email protected]>; Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; [email protected]; PostgreSQL Hackers <[email protected]>
()
On Mon, Nov 30, 2020 at 2:39 PM Kyotaro Horiguchi
<[email protected]> wrote:
>
> At Fri, 27 Nov 2020 13:34:49 +0000, "[email protected]" <[email protected]> wrote in
> > Thank you, Horiguchi-San
> >
> > > I haven't seen a criteria of whether a record is emitted or not for
> > > wal_leve=none.
> > >
> > > We're emitting only redo logs. So I think theoretically we don't need anything
> > > other than the shutdown checkpoint record because we don't perform
> > > recovery and checkpoint record is required at startup.
> > >
> > > RM_XLOG_ID:
> > > XLOG_FPI_FOR_HINT - not needed?
> > > XLOG_FPI - not needed?
> > >
> > > XLOG_CHECKPOINT_SHUTDOWN - must have
> > >
> > > So how about the followings?
> > > XLOG_CHECKPOINT_ONLINE
> > > XLOG_NOOP
> > > XLOG_NEXTOID
> > > XLOG_SWITCH
> > > XLOG_BACKUP_END
> > > XLOG_PARAMETER_CHANGE
> > > XLOG_RESTORE_POINT
> > > XLOG_FPW_CHANGE
> > > XLOG_END_OF_RECOVERY
> > >
> > >
> > > RM_XACT_ID:
> > > XLOG_XACT_COMMIT
> > > XLOG_XACT_PREPARE
> > > XLOG_XACT_ABORT
> > > XLOG_XACT_COMMIT_PREPARED
> > > XLOG_XACT_ABORT_PREPARED
> > > XLOG_XACT_ASSIGNMENT
> > > XLOG_XACT_INVALIDATIONS
> > >
> > > Do we need all of these?
> > No. Strictly speaking, you are right.
> > We still have types of WAL that are not necessarily needed.
> > For example, XLOG_END_OF_RECOVERY is not useful
> > because wal_level=none doesn't recover from any accidents.
> > Or, XLOG_CHECKPOINT_ONLINE is used when we execute CHECKPOINT
> > not for shutting down. Thus we could eliminate more.
>
> Yeah, although it's enough only to restrict non-harmful records
> practically, if we find that only a few kinds of records are needed,
> maybe it's cleaner to allow only required record type(s).
>
> > > And, currenly what decides whether to emit a wal record according to
> > > wal_level is the caller of XLogInsert.
> > Yes.
> >
> > > So doing this at XLogInsert-level means
> > > that we bring the criteria of the necessity of wal-record into xlog layer only for
> > > wal_level=none. I'm not sure it is the right direction.
> > I'm sorry. I didn't understand what "doing this" and "xlog layer" meant.
>
> "doing this" meant filtering record types.
>
> > Did you mean that fixing the caller side of XLogInsert (e.g. CreateCheckPoint)
> > is not the right direction ? Or, fixing the function of XLogInsert is not the right direction ?
>
> Maybe it's right that if we can filter-out records looking only rmid,
> since the xlog facility doesn't need to know about record types of a
> resource manager. But if we need to finer-grained control on the
> record types, I'm afraid that that's wrong.
I also think we should have the caller of XLogInsert() control whether
or not to write a WAL record according to the setting of wal_level
like XLogStandbyInfoActive() and XLogLogicalInfoActive(). Since most
callers seem to assume the wal record will be written when calling to
XLogInsert() I think it's better not to break that assumption.
> However, if we need only
> the XLOG_CHECKPOINT_SHUTDOWN record, it might be better to let
> XLogInsert filter records rather than inserting that filtering code to
> all the caller sites.
>
> > > At Fri, 27 Nov 2020 07:01:16 +0000, "[email protected]"
> > > <[email protected]> wrote in
> > > > I'm afraid "none" doesn't represent the behavior because RM_XLOG_ID and
> > > RM_XACT_ID WAL records, except for XLOG_FPI_*, are emitted. What's the
> > > good name? IIUC, "minimal" is named after the fact that the minimal
> > > amount of WAL necessary for crash recovery is generated. "norecovery" or
> > > "unrecoverable"?
> > Lastly, I found another name which expresses the essential characteristic of this wal_level.
> > How about the name of wal_level="crash_unsafe" ?
> > What did you think ?
>
> I don't dislike "none" since it seems to me practically "none".
Me too.
> It seems rather correct if we actually need only the shutdown checkpoint
> record.
>
> "unrecoverable" is apparently misleading. "crash_unsafe" is precise
> but seems somewhat alien being among "logical", "replica" and
> "minimal".
Since the WAL protocol is for durability I'm concerned the name
'crash_unsafe' (and 'unrecoverable') leads to a contradiction.
Regards,
--
Masahiko Sawada
EnterpriseDB: https://www.enterprisedb.com/
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-23 03:17 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-24 02:18 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-27 06:07 ` Re: Disable WAL logging to speed up data loading Masahiko Sawada <[email protected]>
2020-11-27 07:01 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-27 09:33 ` [email protected] <[email protected]>
1 sibling, 0 replies; 392+ messages in thread
From: [email protected] @ 2020-11-27 09:33 UTC (permalink / raw)
To: [email protected] <[email protected]>; 'Masahiko Sawada' <[email protected]>; +Cc: Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Hi, Tsunakawa-San
> I'm afraid "none" doesn't represent the behavior because RM_XLOG_ID and
> RM_XACT_ID WAL records, except for XLOG_FPI_*, are emitted. What's the
> good name? IIUC, "minimal" is named after the fact that the minimal
> amount of WAL necessary for crash recovery is generated. "norecovery" or
> "unrecoverable"?
Really good point !
Yes, it cannot be helped to generate tiny grain of WALs.
I prefer "unrecoverable" to "none",
which should work to make any users utilize this feature really really carefully.
If there's no strong objection, I'll change the name to it from next time.
Best,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-23 03:17 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-24 02:18 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-27 06:07 ` Re: Disable WAL logging to speed up data loading Masahiko Sawada <[email protected]>
@ 2020-11-27 09:23 ` [email protected] <[email protected]>
2 siblings, 0 replies; 392+ messages in thread
From: [email protected] @ 2020-11-27 09:23 UTC (permalink / raw)
To: 'Masahiko Sawada' <[email protected]>; +Cc: [email protected] <[email protected]>; Fujii Masao <[email protected]>; Laurenz Albe <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Hello, Sawada-San
On Friday, November 27, 2020 3:08 PM Masahiko Sawada <[email protected]> wrote:
> - (errmsg("WAL was generated with wal_level=minimal,
> data may be missing"),
> + (errmsg("WAL was generated with wal_level<=minimal,
> data may be missing"),
> errhint("This happens if you temporarily set
> wal_level=minimal without taking a new base backup.")));
>
> 'wal_level=minimal' in errhint also needs to be changed to
> 'wal_level<=minimal'?
Yeah, thanks. I'll fix this point in the next patch.
> While testing the patch on some workload, I realized that
> XLOG_FPI_FOR_HINT record could still be emitted even when wal_level =
> none. IIUC that WAL record is not necessary during wal_level = none since
> the server cannot be the primary server and the server crash ends up requiring
> to restore the whole database.
That's right. Yeah, I'm aware of the fact that
we can refine the types of WAL. Basically, I thought the amount of
WALs related to XLOG and XACT should be less than that of other types and
generating those doesn't have a serious impact on the peformance.
But anyway, thanks for your advice !
Best,
Takamichi Osumi
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 07:18 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-28 09:55 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 13:05 ` Re: Disable WAL logging to speed up data loading Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-11-16 07:19 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-19 07:50 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-20 12:47 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-23 03:18 ` [email protected] <[email protected]>
1 sibling, 0 replies; 392+ messages in thread
From: [email protected] @ 2020-11-23 03:18 UTC (permalink / raw)
To: [email protected] <[email protected]>; +Cc: 'Fujii Masao' <[email protected]>; Laurenz Albe <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
From: Osumi, Takamichi/大墨 昂道 <[email protected]>
> This time, I updated my patch to address comments below only.
I forgot to mentionthis. I confirmed all review comments are reflected correctly.
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-02 05:03 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-28 04:11 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-10-28 08:46 ` [email protected] <[email protected]>
1 sibling, 0 replies; 392+ messages in thread
From: [email protected] @ 2020-10-28 08:46 UTC (permalink / raw)
To: [email protected] <[email protected]>; +Cc: 'Fujii Masao' <[email protected]>; Kyotaro Horiguchi <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
From: Osumi, Takamichi/大墨 昂道 <[email protected]>
> I wrote and attached the first patch to disable WAL logging.
> This patch passes the regression test of check-world already and is formatted
I think make check-world uses the default setting for wal_level. You need to set wal_level = none and do make installcheck-world.
> I compared two wal_levels both 'minimal' and 'none'.
> For both levels, I measured
> (1) cluster's restore from pg_dumpall output,
> (2) COPY initial data to a defined table as initial data loading, and
> (3) COPY data to a defined table with tuples, 3 times each for all cases.
> After that, calculated the average and the ratio of the loading speed.
> The conclusion is that wal_level=none cuts about 20% of the loading speed
> compared to 'minimal' in the three cases above.
Hmm. I wonder why pg_dumpall's performance increases by as much as 20%. On the contrary to my previous hope, pg_dumpall uses COPY to restore data, so it doesn't emit WAL when wal_level = minimal. (Is it brought by the difference of whether DDL's WAL is emitted or not?)
> Sharing other scenario to measure is welcome.
How about running multiple concurrent data loading sessions when adding data to existing tables with data, so that WAL is the bottleneck? That's the use case of the target customer, isn't it?
> The input data was generated from pgbench with 1000 scale factor.
> It's about 9.3GB. For the table definition or the initial data for appended data
IIRC, I thought the scale factor of 1,000 is 1.5 GB. What displayed 9.3 GB? SELECT pg_database_size() or something?
Below are review comments:
(1)
@@ -449,6 +449,13 @@ XLogInsert(RmgrId rmid, uint8 info)
return EndPos;
}
+ /* Issues WAL only for transaction end and check point */
+ if (wal_level == WAL_LEVEL_NONE && rmid != RM_XLOG_ID)
+ {
+ XLogResetInsertion();
+ return GetLatestCheckPointLSN();
+ }
+
do
This does not emit transaction completion WAL records. Their RM ID is RM_XACT_ID. Also, RM_XLOG_ID includes other kinds of WAL records than the checkpoint WAL record. Correct the comment accordingly. I don't have a good idea on how to represent the RM_XLOG_ID,, but the following might help:
[rmgrlist.h]
/* symbol name, textual name, redo, desc, identify, startup, cleanup */
PG_RMGR(RM_XLOG_ID, "XLOG", xlog_redo, xlog_desc, xlog_identify, NULL, NULL, NULL)
PG_RMGR(RM_XACT_ID, "Transaction", xact_redo, xact_desc, xact_identify, NULL, NULL, NULL)
(2)
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
@@ -2591,10 +2591,10 @@ include_dir 'conf.d'
data to support WAL archiving and replication, including running
read-only queries on a standby server. <literal>minimal</literal> removes all
logging except the information required to recover from a crash or
- immediate shutdown. Finally,
+ immediate shutdown. <literal>none</literal> generates no WAL in any case. Finally,
According to the previous code, "none" emits some kinds of WAL records. So I think we need to come up with a good name and/or description.
(3)
<literal>logical</literal> adds information necessary to support logical
- decoding. Each level includes the information logged at all lower
- levels. This parameter can only be set at server start.
+ decoding. Each level except for <literal>none</literal> includes the
+ information logged at all lower levels. This parameter can only be set at server start.
</para>
Why is this change necessary?
(4)
+ On the other hand, an unexpected crash of the server makes the database cluster
+ inconsistent. For that reason, before utilizing this level, get a full backup of the cluster and
+ backup of the entire operations that are done under the condition that
+ <varname>wal_level</varname> is <literal>none</literal>.
This gives the impression that the user can start the database server and see inconsistent data. The reality is that the database server does not start, isn't it?
(5)
@@ -1751,7 +1752,8 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
Aside from avoiding the time for the archiver or WAL sender to process the
WAL data, doing this will actually make certain commands faster, because
they do not to write WAL at all if <varname>wal_level</varname>
- is <literal>minimal</literal> and the current subtransaction (or top-level
+ is either <literal>minimal</literal> or <literal>minimal</literal>
+ and the current subtransaction (or top-level
transaction) created or truncated the table or index they change. (They
can guarantee crash safety more cheaply by doing
an <function>fsync</function> at the end than by writing WAL.)
This is not correct. In minimal, some conditions need to hold true for WAL to not be generated as described above. OTOH, wal_level = none does not generate WAL unconditionally.
(6)
14.4.9. Some Notes about pg_dump
...
If using WAL archiving or streaming replication, consider disabling them during the restore. To do that, set archive_mode to off, wal_level to minimal, and max_wal_senders to zero before loading the dump. Afterwards, set them back to the right values and take a fresh base backup.
Why don't you refer to wal_level = none here as well?
(7)
@@ -918,10 +918,13 @@ PostmasterMain(int argc, char *argv[])
ReservedBackends, MaxConnections);
ExitPostmaster(1);
}
- if (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level == WAL_LEVEL_MINIMAL)
+ if ((XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level == WAL_LEVEL_NONE) ||
+ (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level == WAL_LEVEL_MINIMAL))
ereport(ERROR,
- (errmsg("WAL archival cannot be enabled when wal_level is \"minimal\"")));
- if (max_wal_senders > 0 && wal_level == WAL_LEVEL_MINIMAL)
+ (errmsg("WAL archival cannot be enabled when wal_level is \"%s\"",
+ wal_level == WAL_LEVEL_MINIMAL ? "minimal" : "none")));
+ if ((max_wal_senders > 0 && wal_level == WAL_LEVEL_NONE) ||
+ (max_wal_senders > 0 && wal_level == WAL_LEVEL_MINIMAL))
ereport(ERROR,
(errmsg("WAL streaming (max_wal_senders > 0) requires wal_level \"replica\" or \"logical\"")));
This style of writing conitions is redundant. You can just change the code to wal_level <= WAL_LEVEL_MINIMAL.
Also, the first message can be '"minimal" or "none"' like the second one.
(8)
@@ -989,6 +992,12 @@ PostmasterMain(int argc, char *argv[])
LocalProcessControlFile(false);
/*
+ * Check some conditions specific to wal_level='none' and ensures the
+ * database isn't inconsistent.
+ */
+ SafelyFinishedNoneLevel();
+
+ /*
This check should be moved to around the beginning of StartupXLOG(). PostmasterMain() is called in multi-user mode. It's not called in single-user mode (postgres --single).
The new function is not necessary. StartupXLOG() can see the control file contents directly.
(9)
+ /*
+ * Detect if we previously crashed under wal_level='none' or not.
+ */
+ unexpected_shutdown = ControlFile->state != DB_SHUTDOWNED &&
+ ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY;
+ if ((ControlFile->wal_level == WAL_LEVEL_NONE && unexpected_shutdown))
+ {
+ ereport(ERROR,
+ (errmsg("Server was unexpectedly shut down when WAL logging was disabled"),
+ errhint("It looks like you need to deploy a new cluster from your full backup again.")));
+ }
+}
Refine the message according to the following message guideline. For example, the primary message has to start with a lower case letter.
https://www.postgresql.org/docs/devel/source.html
(10)
You need to edit this to add none:
src/backend/utils/misc/postgresql.conf.sample
(11)
src/include/access/xlogdefs.h
src/backend/access/transam/varsup.c
Consider modifying the comments in these files that refer to wal_level. Maybe wal_level <= minimal is enough?
(12)
src/include/utils/rel.h
Modify the RelationNeedsWAL() so that it returns false when wal_level = none. Adding wal_level != WAL_LEVEL_NONE is would probably be okay.
(13)
@@ -161,7 +161,8 @@ extern int XLogArchiveMode;
/* WAL levels */
typedef enum WalLevel
{
- WAL_LEVEL_MINIMAL = 0,
+ WAL_LEVEL_NONE = 0,
+ WAL_LEVEL_MINIMAL,
WAL_LEVEL_REPLICA,
WAL_LEVEL_LOGICAL
} WalLevel;
I'm a bit concerned about if we can change the values of existing symbols, because wal_level setting is stored in pg_control file. Having a quick look at source code, there seems to be no problem. However, I'm not sure about pg_upgrade. Can you try, for example,
1. Create the database cluster with an older version, say, PG 13.
2. Start and stop the database server.
3. Run pg_controldata and see that it prints replica for the wal_level value.
4. Upgrade the database cluster with pg_upgrade.
5. Run pg_controldata and see the wal_level value.
If you change the values of existing symbols like your patch, you need to bump PG_CONTROL_VERSION.
If you find we can't tchange the existing values, you can probably set WAL_LEVEL_NONE to -1.
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
@ 2020-11-10 14:33 ` Stephen Frost <[email protected]>
2020-11-11 08:35 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
1 sibling, 1 reply; 392+ messages in thread
From: Stephen Frost @ 2020-11-10 14:33 UTC (permalink / raw)
To: Kyotaro Horiguchi <[email protected]>; +Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Greetings,
* Kyotaro Horiguchi ([email protected]) wrote:
> For fuel(?) of the discussion, I tried a very-quick PoC for in-place
> ALTER TABLE SET LOGGED/UNLOGGED and resulted as attached. After some
> trials of several ways, I drifted to the following way after poking
> several ways.
>
> 1. Flip BM_PERMANENT of active buffers
> 2. adding/removing init fork
> 3. sync files,
> 4. Flip pg_class.relpersistence.
>
> It always skips table copy in the SET UNLOGGED case, and only when
> wal_level=minimal in the SET LOGGED case. Crash recovery seems
> working by some brief testing by hand.
Somehow missed that this patch more-or-less does what I was referring to
down-thread, but I did want to mention that it looks like it's missing a
necessary FlushRelationBuffers() call before the sync, otherwise there
could be dirty buffers for the relation that's being set to LOGGED (with
wal_level=minimal), which wouldn't be good. See the comments above
smgrimmedsync().
> Of course, I haven't performed intensive test on it.
Reading through the thread, it didn't seem very clear, but we should
definitely make sure that it does the right thing on replicas when going
between unlogged and logged (and between logged and unlogged too), of
course.
Thanks,
Stephen
Attachments:
[application/pgp-signature] signature.asc (819B, ../../[email protected]/2-signature.asc)
download
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-11-10 14:33 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
@ 2020-11-11 08:35 ` Kyotaro Horiguchi <[email protected]>
2020-11-11 09:24 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: Kyotaro Horiguchi @ 2020-11-11 08:35 UTC (permalink / raw)
To: [email protected]; +Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
At Tue, 10 Nov 2020 09:33:12 -0500, Stephen Frost <[email protected]> wrote in
> Greetings,
>
> * Kyotaro Horiguchi ([email protected]) wrote:
> > For fuel(?) of the discussion, I tried a very-quick PoC for in-place
> > ALTER TABLE SET LOGGED/UNLOGGED and resulted as attached. After some
> > trials of several ways, I drifted to the following way after poking
> > several ways.
> >
> > 1. Flip BM_PERMANENT of active buffers
> > 2. adding/removing init fork
> > 3. sync files,
> > 4. Flip pg_class.relpersistence.
> >
> > It always skips table copy in the SET UNLOGGED case, and only when
> > wal_level=minimal in the SET LOGGED case. Crash recovery seems
> > working by some brief testing by hand.
>
> Somehow missed that this patch more-or-less does what I was referring to
> down-thread, but I did want to mention that it looks like it's missing a
> necessary FlushRelationBuffers() call before the sync, otherwise there
> could be dirty buffers for the relation that's being set to LOGGED (with
> wal_level=minimal), which wouldn't be good. See the comments above
> smgrimmedsync().
>
> > Of course, I haven't performed intensive test on it.
>
> Reading through the thread, it didn't seem very clear, but we should
> definitely make sure that it does the right thing on replicas when going
> between unlogged and logged (and between logged and unlogged too), of
> course.
>
> Thanks,
Thanks! Since this feature is different from the feature that is
being proposed in this thhead, I started another thread for this
feature.
https://www.postgresql.org/message-id/[email protected]
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-11-10 14:33 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-11 08:35 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
@ 2020-11-11 09:24 ` [email protected] <[email protected]>
2020-11-11 14:36 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: [email protected] @ 2020-11-11 09:24 UTC (permalink / raw)
To: 'Kyotaro Horiguchi' <[email protected]>; [email protected] <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
From: Kyotaro Horiguchi <[email protected]>
> Thanks! Since this feature is different from the feature that is
> being proposed in this thhead, I started another thread for this
> feature.
>
> https://www.postgresql.org/message-id/20201111.173317.460890039962481
> [email protected]
Thank you, Horiguchi-san(^^) I was just about to ask you to separate the thread, because I think both features are good:
* ALTER TABLE SET UNLOGGED/LOGGED without data copy
Good:
- Does not require server restart (if this feature can be used in all wal_level settings).
Bad:
- The user has to maintain and modify some scripts to use ALTER TABLE when adding or removing the tables/partitions to load data into. For example, if the data loading job specifies a partitioned table, he may forget to add ALTER TABLE for new partitions, resulting in slow data loading.
* wal_level = none
Good:
- Easy to use. The user does not have to be aware of what tables are loaded. This can come in handy when migrating from an older version or another DBMS, building test databases, and consolidating databases.
Bad:
- Requires server restart.
* Both features
Bad:
- Requires taking database backup.
- Requires rebuilding the standby.
Sadly, the new thread's title includes a spelling mistake of extra r -- "In-placre". (I hope this won't prevent the search hit in the mail archive.)
I expect both features will be able to meet our customer's needs. The worst scenario (I don't want to imagine!) is that neither feature fails to be committed. So, let us continue both features. I'll join Horiguchi-san's new thread, and please help us here too. (I'll catch up with the recent discussion in this thread and reply.)
> Couldn't we have something like the following?
>
> ALTER TABLE table1, table2, table3 SET UNLOGGED;
>
> That is, multiple target object specification in ALTER TABLE sttatement.
Likewise, can't we do ALTER TABLE SET UNLOGGED/LOGGED against a partitioned table? Currently, the statement succeeds but none of the partitioned table nor its partitions is set unlogged (pg_class.relpersistence remains 'p'). Is this intended? If it's a bug, I'm willing to fix it so that it reports an eror. Of course, it's good to make all partitions unlogged at once.
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* Re: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-11-10 14:33 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-11 08:35 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-11-11 09:24 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
@ 2020-11-11 14:36 ` Stephen Frost <[email protected]>
2020-11-12 02:46 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
0 siblings, 1 reply; 392+ messages in thread
From: Stephen Frost @ 2020-11-11 14:36 UTC (permalink / raw)
To: [email protected] <[email protected]>; +Cc: 'Kyotaro Horiguchi' <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Greetings,
* [email protected] ([email protected]) wrote:
> * ALTER TABLE SET UNLOGGED/LOGGED without data copy
> Good:
> - Does not require server restart (if this feature can be used in all wal_level settings).
>
> Bad:
> - The user has to maintain and modify some scripts to use ALTER TABLE when adding or removing the tables/partitions to load data into. For example, if the data loading job specifies a partitioned table, he may forget to add ALTER TABLE for new partitions, resulting in slow data loading.
I'm not sure that I see this as really being much of an issue. Perhaps
there are some things we can do, as I mentioned before, to make it
easier for users to have tables be created as unlogged from the start,
or to be able to ALTER TABLE a bunch of tables at once (using all in
tablespace, or maybe having an ALTER TABLE on a partitioned table
cascade to the partitions), but overall the risk here seems very low-
clearly whatever processing is running to load the data into a
particular table knows what the table is and adding an ALTER TABLE into
it would be trivial.
Specifically, for a partitioned table, I would think the load would go
something like:
CREATE UNLOGGED TABLE ...
load all of the data
ALTER TABLE ... SET LOGGED
ALTER TABLE ... ATTACH PARTITION
If the data load could all be done in a single transaction then you
wouldn't even need to create the table as UNLOGGED or issue the SET
LOGGED, with wal_level=minimal, you just need to create the table in the
same transaction that you do the data load in.
> * wal_level = none
> Good:
> - Easy to use. The user does not have to be aware of what tables are loaded. This can come in handy when migrating from an older version or another DBMS, building test databases, and consolidating databases.
A GUC that allowed users to set a default for newly created tables to be
unlogged would also address this.
> Bad:
> - Requires server restart.
Introducing yet another wal_level strikes me as a very large step, one
that the arguments presented here for why it'd be worth it don't come
anywhere near justifying that step.
> I expect both features will be able to meet our customer's needs. The worst scenario (I don't want to imagine!) is that neither feature fails to be committed. So, let us continue both features. I'll join Horiguchi-san's new thread, and please help us here too. (I'll catch up with the recent discussion in this thread and reply.)
While you're certainly welcome to spend your time where you wish to, if,
as you say, making these changes to how tables can be switched from
unlogged to logged with wal_level=minimal meets this use-case then that
strikes me as definitely the right approach and removes any
justification for adding another wal_level.
> > Couldn't we have something like the following?
> >
> > ALTER TABLE table1, table2, table3 SET UNLOGGED;
> >
> > That is, multiple target object specification in ALTER TABLE sttatement.
>
> Likewise, can't we do ALTER TABLE SET UNLOGGED/LOGGED against a partitioned table? Currently, the statement succeeds but none of the partitioned table nor its partitions is set unlogged (pg_class.relpersistence remains 'p'). Is this intended? If it's a bug, I'm willing to fix it so that it reports an eror. Of course, it's good to make all partitions unlogged at once.
I agree that this doesn't seem quite right and considering the way other
commands work like CREATE INDEX, I would think that doing such an ALTER
TABLE would recurse to the individual partitions (skipping over any
which are already set to the persistance desired..).
Thanks,
Stephen
Attachments:
[application/pgp-signature] signature.asc (819B, ../../[email protected]/2-signature.asc)
download
^ permalink raw reply [nested|flat] 392+ messages in thread
* RE: Disable WAL logging to speed up data loading
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 12:40 ` Re: Disable WAL logging to speed up data loading Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 01:01 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 03:04 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-01 03:58 ` Re: Disable WAL logging to speed up data loading Fujii Masao <[email protected]>
2020-10-01 04:38 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-10-02 01:06 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-11-10 14:33 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
2020-11-11 08:35 ` Re: Disable WAL logging to speed up data loading Kyotaro Horiguchi <[email protected]>
2020-11-11 09:24 ` RE: Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-11-11 14:36 ` Re: Disable WAL logging to speed up data loading Stephen Frost <[email protected]>
@ 2020-11-12 02:46 ` [email protected] <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: [email protected] @ 2020-11-12 02:46 UTC (permalink / raw)
To: 'Stephen Frost' <[email protected]>; +Cc: 'Kyotaro Horiguchi' <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
From: Stephen Frost <[email protected]>
> I'm not sure that I see this as really being much of an issue. Perhaps there are
> some things we can do, as I mentioned before, to make it easier for users to
> have tables be created as unlogged from the start, or to be able to ALTER
> TABLE a bunch of tables at once (using all in tablespace, or maybe having an
> ALTER TABLE on a partitioned table cascade to the partitions), but overall the
> risk here seems very low- clearly whatever processing is running to load the
> data into a particular table knows what the table is and adding an ALTER
> TABLE into it would be trivial.
Thank you for your opinion. I'm glad to see great people like Robert, Magnus and you have given comments (honestly, I didn't expect this trivial feature wouldn't get attention.) I'll read those mails from the oldest including this, and reply to them if needed.
> > Likewise, can't we do ALTER TABLE SET UNLOGGED/LOGGED against a
> partitioned table? Currently, the statement succeeds but none of the
> partitioned table nor its partitions is set unlogged (pg_class.relpersistence
> remains 'p'). Is this intended? If it's a bug, I'm willing to fix it so that it reports
> an eror. Of course, it's good to make all partitions unlogged at once.
>
> I agree that this doesn't seem quite right and considering the way other
> commands work like CREATE INDEX, I would think that doing such an ALTER
> TABLE would recurse to the individual partitions (skipping over any which are
> already set to the persistance desired..).
OK, I'll try to propagate the alteration to partitions. (I wish the fix will be easy, but I'm afraid some devil is lurking...) I'd appreciate it if someone could kindly point out the devil if he/she knows the past history.
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 392+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 392+ messages in thread
end of thread, other threads:[~2025-08-04 22:05 UTC | newest]
Thread overview: 392+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-09-29 08:28 Disable WAL logging to speed up data loading [email protected] <[email protected]>
2020-09-29 09:40 ` Amul Sul <[email protected]>
2020-09-30 02:33 ` [email protected] <[email protected]>
2020-09-29 12:40 ` Ashutosh Bapat <[email protected]>
2020-09-30 03:10 ` [email protected] <[email protected]>
2020-10-01 01:01 ` Fujii Masao <[email protected]>
2020-10-01 02:51 ` Kyotaro Horiguchi <[email protected]>
2020-10-01 03:04 ` [email protected] <[email protected]>
2020-10-01 03:58 ` Fujii Masao <[email protected]>
2020-10-01 04:38 ` Kyotaro Horiguchi <[email protected]>
2020-10-01 08:14 ` [email protected] <[email protected]>
2020-10-02 01:06 ` Kyotaro Horiguchi <[email protected]>
2020-10-02 01:56 ` Fujii Masao <[email protected]>
2020-10-02 04:38 ` Kyotaro Horiguchi <[email protected]>
2020-10-02 04:51 ` Kyotaro Horiguchi <[email protected]>
2020-10-02 05:07 ` Kyotaro Horiguchi <[email protected]>
2020-10-02 05:03 ` [email protected] <[email protected]>
2020-10-28 04:11 ` [email protected] <[email protected]>
2020-10-28 07:18 ` Laurenz Albe <[email protected]>
2020-10-28 09:55 ` [email protected] <[email protected]>
2020-10-28 13:05 ` Laurenz Albe <[email protected]>
2020-10-28 20:32 ` Laurenz Albe <[email protected]>
2020-10-29 00:07 ` [email protected] <[email protected]>
2020-10-29 10:24 ` Laurenz Albe <[email protected]>
2020-10-29 02:42 ` Fujii Masao <[email protected]>
2020-10-29 10:21 ` Laurenz Albe <[email protected]>
2020-10-29 20:00 ` Fujii Masao <[email protected]>
2020-10-30 04:32 ` Masahiko Sawada <[email protected]>
2020-11-02 00:27 ` [email protected] <[email protected]>
2020-10-30 12:28 ` Laurenz Albe <[email protected]>
2020-11-02 15:28 ` Robert Haas <[email protected]>
2020-11-02 15:35 ` Magnus Hagander <[email protected]>
2020-11-02 18:01 ` Stephen Frost <[email protected]>
2020-11-09 06:30 ` [email protected] <[email protected]>
2020-11-09 15:18 ` Stephen Frost <[email protected]>
2020-11-09 17:05 ` David G. Johnston <[email protected]>
2020-11-09 17:36 ` Stephen Frost <[email protected]>
2020-11-09 18:20 ` David G. Johnston <[email protected]>
2020-11-09 19:26 ` Stephen Frost <[email protected]>
2020-11-17 02:49 ` [email protected] <[email protected]>
2020-11-10 00:59 ` Kyotaro Horiguchi <[email protected]>
2020-11-10 14:16 ` Stephen Frost <[email protected]>
2020-11-11 03:07 ` [email protected] <[email protected]>
2020-11-19 02:07 ` [email protected] <[email protected]>
2020-11-19 03:45 ` [email protected] <[email protected]>
2020-11-19 05:24 ` [email protected] <[email protected]>
2020-11-19 07:50 ` Laurenz Albe <[email protected]>
2020-11-19 10:26 ` [email protected] <[email protected]>
2020-11-19 16:04 ` Stephen Frost <[email protected]>
2020-11-20 00:22 ` Kyotaro Horiguchi <[email protected]>
2020-11-20 00:32 ` [email protected] <[email protected]>
2020-11-20 01:19 ` [email protected] <[email protected]>
2020-11-20 16:03 ` Stephen Frost <[email protected]>
2020-11-17 01:45 ` [email protected] <[email protected]>
2020-11-16 07:19 ` [email protected] <[email protected]>
2020-11-19 07:50 ` [email protected] <[email protected]>
2020-11-20 12:47 ` [email protected] <[email protected]>
2020-11-23 03:17 ` [email protected] <[email protected]>
2020-11-24 02:18 ` [email protected] <[email protected]>
2020-11-27 06:07 ` Masahiko Sawada <[email protected]>
2020-11-27 06:38 ` Kyotaro Horiguchi <[email protected]>
2020-11-27 07:01 ` [email protected] <[email protected]>
2020-11-27 08:35 ` Kyotaro Horiguchi <[email protected]>
2020-11-27 13:34 ` [email protected] <[email protected]>
2020-11-30 05:07 ` Kyotaro Horiguchi <[email protected]>
2020-11-30 06:45 ` Masahiko Sawada <[email protected]>
2020-11-27 09:33 ` [email protected] <[email protected]>
2020-11-27 09:23 ` [email protected] <[email protected]>
2020-11-23 03:18 ` [email protected] <[email protected]>
2020-10-28 08:46 ` [email protected] <[email protected]>
2020-11-10 14:33 ` Stephen Frost <[email protected]>
2020-11-11 08:35 ` Kyotaro Horiguchi <[email protected]>
2020-11-11 09:24 ` [email protected] <[email protected]>
2020-11-11 14:36 ` Stephen Frost <[email protected]>
2020-11-12 02:46 ` [email protected] <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace 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