ToDo: show size of partitioned table

Started by Pavel Stehulealmost 8 years ago106 messageshackers
Jump to latest
#1Pavel Stehule
pavel.stehule@gmail.com

Hi

postgres=# SELECT count(*) from data;
┌─────────┐
│ count │
╞═════════╡
│ 1000000 │
└─────────┘
(1 row)

\dt+ can display actual size of partitioned table data - now zero is
displayed

postgres=# \dt+ data
List of relations
┌────────┬──────┬───────┬───────┬─────────┬─────────────┐
│ Schema │ Name │ Type │ Owner │ Size │ Description │
╞════════╪══════╪═══════╪═══════╪═════════╪═════════════╡
│ public │ data │ table │ pavel │ 0 bytes │ │
└────────┴──────┴───────┴───────┴─────────┴─────────────┘
(1 row)

postgres=# \dt+ data*
List of relations
┌────────┬────────────┬───────┬───────┬─────────┬─────────────┐
│ Schema │ Name │ Type │ Owner │ Size │ Description │
╞════════╪════════════╪═══════╪═══════╪═════════╪═════════════╡
│ public │ data │ table │ pavel │ 0 bytes │ │
│ public │ data_2016 │ table │ pavel │ 17 MB │ │
│ public │ data_2017 │ table │ pavel │ 17 MB │ │
│ public │ data_other │ table │ pavel │ 8224 kB │ │
└────────┴────────────┴───────┴───────┴─────────┴─────────────┘
(4 rows)

or we can introduce some option for display only partitioned tables without
partitions.

Regards

Pavel

#2Ashutosh Bapat
ashutosh.bapat@enterprisedb.com
In reply to: Pavel Stehule (#1)
Re: ToDo: show size of partitioned table

On Fri, Jun 1, 2018 at 12:56 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:

Hi

postgres=# SELECT count(*) from data;
┌─────────┐
│ count │
╞═════════╡
│ 1000000 │
└─────────┘
(1 row)

\dt+ can display actual size of partitioned table data - now zero is
displayed

postgres=# \dt+ data
List of relations
┌────────┬──────┬───────┬───────┬─────────┬─────────────┐
│ Schema │ Name │ Type │ Owner │ Size │ Description │
╞════════╪══════╪═══════╪═══════╪═════════╪═════════════╡
│ public │ data │ table │ pavel │ 0 bytes │ │
└────────┴──────┴───────┴───────┴─────────┴─────────────┘
(1 row)

I think we should at least display "Type" as "partitioned table" for a
partitioned table, so that it's easy to understand why the size is 0;
partitioned tables do not hold any data by themselves.

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

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Ashutosh Bapat (#2)
Re: ToDo: show size of partitioned table

2018-06-01 17:15 GMT+02:00 Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>:

On Fri, Jun 1, 2018 at 12:56 AM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

Hi

postgres=# SELECT count(*) from data;
┌─────────┐
│ count │
╞═════════╡
│ 1000000 │
└─────────┘
(1 row)

\dt+ can display actual size of partitioned table data - now zero is
displayed

postgres=# \dt+ data
List of relations
┌────────┬──────┬───────┬───────┬─────────┬─────────────┐
│ Schema │ Name │ Type │ Owner │ Size │ Description │
╞════════╪══════╪═══════╪═══════╪═════════╪═════════════╡
│ public │ data │ table │ pavel │ 0 bytes │ │
└────────┴──────┴───────┴───────┴─────────┴─────────────┘
(1 row)

I think we should at least display "Type" as "partitioned table" for a
partitioned table, so that it's easy to understand why the size is 0;
partitioned tables do not hold any data by themselves.

should be.

Some is missing still - there is not any total size across all partitions.

maybe new command like

\dtP+ .. show partitioned tables and their size

Regards

Pavel

Show quoted text

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

#4Jeevan Ladhe
jeevan.ladhe@enterprisedb.com
In reply to: Pavel Stehule (#3)
Re: ToDo: show size of partitioned table

On Fri, Jun 1, 2018 at 8:51 PM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

2018-06-01 17:15 GMT+02:00 Ashutosh Bapat <ashutosh.bapat@enterprisedb.com

:

On Fri, Jun 1, 2018 at 12:56 AM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

Hi

postgres=# SELECT count(*) from data;
┌─────────┐
│ count │
╞═════════╡
│ 1000000 │
└─────────┘
(1 row)

\dt+ can display actual size of partitioned table data - now zero is
displayed

postgres=# \dt+ data
List of relations
┌────────┬──────┬───────┬───────┬─────────┬─────────────┐
│ Schema │ Name │ Type │ Owner │ Size │ Description │
╞════════╪══════╪═══════╪═══════╪═════════╪═════════════╡
│ public │ data │ table │ pavel │ 0 bytes │ │
└────────┴──────┴───────┴───────┴─────────┴─────────────┘
(1 row)

I think we should at least display "Type" as "partitioned table" for a
partitioned table, so that it's easy to understand why the size is 0;
partitioned tables do not hold any data by themselves.

should be.

Yes, or maybe we can add that info in "Description".

Some is missing still - there is not any total size across all partitions.

maybe new command like

\dtP+ .. show partitioned tables and their size

+1

Regards,
Jeevan Ladhe

#5Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Ashutosh Bapat (#2)
Re: ToDo: show size of partitioned table

On 2018/06/02 0:15, Ashutosh Bapat wrote:

I think we should at least display "Type" as "partitioned table" for a
partitioned table, so that it's easy to understand why the size is 0;
partitioned tables do not hold any data by themselves.

There was a long discussion last year (during PG 10 beta period), such as
[1]: /messages/by-id/7dfc13c5-d6b7-1ff1-4bef-d75d6d2f76d9@lab.ntt.co.jp
finally do it for PG 12, if not PG 11.

Regarding showing the size of partitioned tables, there are many opinions
and it's not clear if showing it in \dt itself is appropriate. For one,
there is no pg_relation_size() or pg_table_size() equivalent in the
backend for aggregating the size of all tables in a partition tree and I
think people are not quite on board about having such a function in the
backend [2]/messages/by-id/495cec7e-f8d9-7e13-4807-90dbf4eec4ea@lab.ntt.co.jp.

Thanks,
Amit

[1]: /messages/by-id/7dfc13c5-d6b7-1ff1-4bef-d75d6d2f76d9@lab.ntt.co.jp
/messages/by-id/7dfc13c5-d6b7-1ff1-4bef-d75d6d2f76d9@lab.ntt.co.jp

[2]: /messages/by-id/495cec7e-f8d9-7e13-4807-90dbf4eec4ea@lab.ntt.co.jp
/messages/by-id/495cec7e-f8d9-7e13-4807-90dbf4eec4ea@lab.ntt.co.jp

#6Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#5)
Re: ToDo: show size of partitioned table

2018-06-20 7:44 GMT+02:00 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>:

On 2018/06/02 0:15, Ashutosh Bapat wrote:

I think we should at least display "Type" as "partitioned table" for a
partitioned table, so that it's easy to understand why the size is 0;
partitioned tables do not hold any data by themselves.

There was a long discussion last year (during PG 10 beta period), such as
[1], and it seems most of us agreed to doing the above. Maybe, we should
finally do it for PG 12, if not PG 11.

Regarding showing the size of partitioned tables, there are many opinions
and it's not clear if showing it in \dt itself is appropriate. For one,
there is no pg_relation_size() or pg_table_size() equivalent in the
backend for aggregating the size of all tables in a partition tree and I
think people are not quite on board about having such a function in the
backend [2].

Now, the number of partitions can be low, but if the Postgres can better
process high number of partitions, then for some tables we can have
hundreds partitions.

Then usual \dt can be not too much usable. The aggregation can be done on
client side. But maybe this idea is premature. Now, for PG 12, we can start
with

\dtP+ command for showing partition tables only with aggregate size via all
related partitions.

Is it acceptable idea?

Regards

Pavel

Show quoted text

Thanks,
Amit

[1]
/messages/by-id/7dfc13c5-d6b7-
1ff1-4bef-d75d6d2f76d9%40lab.ntt.co.jp

[2]
/messages/by-id/495cec7e-f8d9-
7e13-4807-90dbf4eec4ea%40lab.ntt.co.jp

#7Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#6)
Re: ToDo: show size of partitioned table

On 2018/06/20 16:21, Pavel Stehule wrote:

2018-06-20 7:44 GMT+02:00 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>:

On 2018/06/02 0:15, Ashutosh Bapat wrote:

I think we should at least display "Type" as "partitioned table" for a
partitioned table, so that it's easy to understand why the size is 0;
partitioned tables do not hold any data by themselves.

There was a long discussion last year (during PG 10 beta period), such as
[1], and it seems most of us agreed to doing the above. Maybe, we should
finally do it for PG 12, if not PG 11.

Regarding showing the size of partitioned tables, there are many opinions
and it's not clear if showing it in \dt itself is appropriate. For one,
there is no pg_relation_size() or pg_table_size() equivalent in the
backend for aggregating the size of all tables in a partition tree and I
think people are not quite on board about having such a function in the
backend [2].

Now, the number of partitions can be low, but if the Postgres can better
process high number of partitions, then for some tables we can have
hundreds partitions.

Then usual \dt can be not too much usable. The aggregation can be done on
client side. But maybe this idea is premature. Now, for PG 12, we can start
with

\dtP+ command for showing partition tables only with aggregate size via all
related partitions.

Is it acceptable idea?

Do you mean \dt continues to show size 0 for partitioned tables, but with
the new option (\dtP+) shows the actual size by aggregating across
partitions? +1 to such a feature, but we need to agree on an acceptable
implementation for that. How does the aggregation happen:

1. In a new dedicated function in the backend (parallel to pg_table_size)?

or

2. psql issues a separate query to compute the total size of a partition
tree

For option 2, I had posted a patch that simplifies writing such a query
and posted that here:

/messages/by-id/7a9c5328-5328-52a3-2a3d-bf1434b4dd1d@lab.ntt.co.jp

With that patch, the query to get the total size of a partition tree
becomes as simple as:

select sum(pg_table_size(p)) as size
from pg_get_inheritance_tables('partitioned_table_name') p

Thanks,
Amit

#8Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#7)
Re: ToDo: show size of partitioned table

2018-06-20 9:44 GMT+02:00 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>:

On 2018/06/20 16:21, Pavel Stehule wrote:

2018-06-20 7:44 GMT+02:00 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>:

On 2018/06/02 0:15, Ashutosh Bapat wrote:

I think we should at least display "Type" as "partitioned table" for a
partitioned table, so that it's easy to understand why the size is 0;
partitioned tables do not hold any data by themselves.

There was a long discussion last year (during PG 10 beta period), such

as

[1], and it seems most of us agreed to doing the above. Maybe, we

should

finally do it for PG 12, if not PG 11.

Regarding showing the size of partitioned tables, there are many

opinions

and it's not clear if showing it in \dt itself is appropriate. For one,
there is no pg_relation_size() or pg_table_size() equivalent in the
backend for aggregating the size of all tables in a partition tree and I
think people are not quite on board about having such a function in the
backend [2].

Now, the number of partitions can be low, but if the Postgres can better
process high number of partitions, then for some tables we can have
hundreds partitions.

Then usual \dt can be not too much usable. The aggregation can be done on
client side. But maybe this idea is premature. Now, for PG 12, we can

start

with

\dtP+ command for showing partition tables only with aggregate size via

all

related partitions.

Is it acceptable idea?

Do you mean \dt continues to show size 0 for partitioned tables, but with
the new option (\dtP+) shows the actual size by aggregating across
partitions? +1 to such a feature, but we need to agree on an acceptable
implementation for that. How does the aggregation happen:

yes - my proposal is no change for \dt for now. I think so we will have to
change it, when partitioning will be more common and number of partitions
will be high. But it is not today.

\dtP shows only partitions tables (like \dtS shows only system tables),
with "+" shows sum of all related partitions.

1. In a new dedicated function in the backend (parallel to pg_table_size)?

or

2. psql issues a separate query to compute the total size of a partition
tree

In this moment we can simply do sum on client side, so it is related to @2.

For option 2, I had posted a patch that simplifies writing such a query
and posted that here:

/messages/by-id/7a9c5328-5328-52a3-
2a3d-bf1434b4dd1d%40lab.ntt.co.jp

With that patch, the query to get the total size of a partition tree
becomes as simple as:

select sum(pg_table_size(p)) as size
from pg_get_inheritance_tables('partitioned_table_name') p

good to know it. Thank you. Do you think so your patch should be included
to this feature or will be processed independently?

Regards

Pavel

Show quoted text

Thanks,
Amit

#9Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#8)
Re: ToDo: show size of partitioned table

On 2018/06/20 16:50, Pavel Stehule wrote:

2018-06-20 9:44 GMT+02:00 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>:

Do you mean \dt continues to show size 0 for partitioned tables, but with
the new option (\dtP+) shows the actual size by aggregating across
partitions? +1 to such a feature, but we need to agree on an acceptable
implementation for that. How does the aggregation happen:

yes - my proposal is no change for \dt for now. I think so we will have to
change it, when partitioning will be more common and number of partitions
will be high. But it is not today.

\dtP shows only partitions tables (like \dtS shows only system tables),
with "+" shows sum of all related partitions.

Ah, okay. That makes sense.

1. In a new dedicated function in the backend (parallel to pg_table_size)?

or

2. psql issues a separate query to compute the total size of a partition
tree

In this moment we can simply do sum on client side, so it is related to @2.

I see, okay.

For option 2, I had posted a patch that simplifies writing such a query
and posted that here:

/messages/by-id/7a9c5328-5328-52a3-
2a3d-bf1434b4dd1d%40lab.ntt.co.jp

With that patch, the query to get the total size of a partition tree
becomes as simple as:

select sum(pg_table_size(p)) as size
from pg_get_inheritance_tables('partitioned_table_name') p

good to know it. Thank you. Do you think so your patch should be included
to this feature or will be processed independently?

It seems that it would be useful on its own, as people may want to do
various things once we provide them pg_get_inheritance_table.

Thanks,
Amit

#10Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#9)
Re: ToDo: show size of partitioned table

2018-06-20 10:03 GMT+02:00 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>:

On 2018/06/20 16:50, Pavel Stehule wrote:

2018-06-20 9:44 GMT+02:00 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>:

Do you mean \dt continues to show size 0 for partitioned tables, but

with

the new option (\dtP+) shows the actual size by aggregating across
partitions? +1 to such a feature, but we need to agree on an acceptable
implementation for that. How does the aggregation happen:

yes - my proposal is no change for \dt for now. I think so we will have

to

change it, when partitioning will be more common and number of partitions
will be high. But it is not today.

\dtP shows only partitions tables (like \dtS shows only system tables),
with "+" shows sum of all related partitions.

Ah, okay. That makes sense.

1. In a new dedicated function in the backend (parallel to

pg_table_size)?

or

2. psql issues a separate query to compute the total size of a partition
tree

In this moment we can simply do sum on client side, so it is related to

@2.

I see, okay.

For option 2, I had posted a patch that simplifies writing such a query
and posted that here:

/messages/by-id/7a9c5328-5328-52a3-
2a3d-bf1434b4dd1d%40lab.ntt.co.jp

With that patch, the query to get the total size of a partition tree
becomes as simple as:

select sum(pg_table_size(p)) as size
from pg_get_inheritance_tables('partitioned_table_name') p

good to know it. Thank you. Do you think so your patch should be included
to this feature or will be processed independently?

It seems that it would be useful on its own, as people may want to do
various things once we provide them pg_get_inheritance_table.

ok

I'll prepare patch and I'll do note about dependency on your patch.

Regards

Pavel

Show quoted text

Thanks,
Amit

#11Pavel Stehule
pavel.stehule@gmail.com
In reply to: Pavel Stehule (#10)
Re: ToDo: show size of partitioned table

Hi

I am sending a prototype of patch. Now, it calculates size of partitioned
tables with recursive query. When any more simple method will be possible,
the size calculation will be changed.

postgres=# \dt+
                       List of relations
+--------+------------+-------+-------+---------+-------------+
| Schema |    Name    | Type  | Owner |  Size   | Description |
+--------+------------+-------+-------+---------+-------------+
| public | data       | table | pavel | 0 bytes |             |
| public | data_2016  | table | pavel | 15 MB   |             |
| public | data_2017  | table | pavel | 15 MB   |             |
| public | data_other | table | pavel | 11 MB   |             |
+--------+------------+-------+-------+---------+-------------+
(4 rows)
postgres=# \dP+
          List of partitioned tables
+--------+------+-------+-------+-------------+
| Schema | Name | Owner | Size  | Description |
+--------+------+-------+-------+-------------+
| public | data | pavel | 42 MB |             |
+--------+------+-------+-------+-------------+
(1 row)

Regards

Pavel

p.s. Another patch can be replacement of relation type from "table" to
"partitioned table"

postgres=# \dt+
                             List of relations
+--------+------------+-------------------+-------+---------+-------------+
| Schema |    Name    |       Type        | Owner |  Size   | Description |
+--------+------------+-------------------+-------+---------+-------------+
| public | data       | partitioned table | pavel | 0 bytes |             |
| public | data_2016  | table             | pavel | 15 MB   |             |
| public | data_2017  | table             | pavel | 15 MB   |             |
| public | data_other | table             | pavel | 11 MB   |             |
+--------+------------+-------------------+-------+---------+-------------+
(4 rows)

A patch is simple for this case

diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index c3bdf8555d..491e58eb29 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -3490,8 +3490,8 @@ listTables(const char *tabtypes, const char *pattern,
bool verbose, bool showSys
                      gettext_noop("sequence"),
                      gettext_noop("special"),
                      gettext_noop("foreign table"),
-                     gettext_noop("table"),    /* partitioned table */
-                     gettext_noop("index"),    /* partitioned index */
+                     gettext_noop("partitioned table"),    /* partitioned
table */
+                     gettext_noop("partitioned index"),    /* partitioned
index */
                      gettext_noop("Type"),
                      gettext_noop("Owner"));

Attachments:

psql-dP-initial.patchtext/x-patch; charset=US-ASCII; name=psql-dP-initial.patchDownload+140-2
#12Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#11)
Re: ToDo: show size of partitioned table

Hi Pavel.

On 2018/07/23 20:46, Pavel Stehule wrote:

Hi

I am sending a prototype of patch. Now, it calculates size of partitioned
tables with recursive query. When any more simple method will be possible,
the size calculation will be changed.

postgres=# \dt+
List of relations
+--------+------------+-------+-------+---------+-------------+
| Schema |    Name    | Type  | Owner |  Size   | Description |
+--------+------------+-------+-------+---------+-------------+
| public | data       | table | pavel | 0 bytes |             |
| public | data_2016  | table | pavel | 15 MB   |             |
| public | data_2017  | table | pavel | 15 MB   |             |
| public | data_other | table | pavel | 11 MB   |             |
+--------+------------+-------+-------+---------+-------------+
(4 rows)
postgres=# \dP+
List of partitioned tables
+--------+------+-------+-------+-------------+
| Schema | Name | Owner | Size  | Description |
+--------+------+-------+-------+-------------+
| public | data | pavel | 42 MB |             |
+--------+------+-------+-------+-------------+
(1 row)

This looks nice, although I haven't looked at the patch yet. Also, as you
said, we could later replace the method of directly querying pg_inherits
by something else.

p.s. Another patch can be replacement of relation type from "table" to
"partitioned table"

postgres=# \dt+
List of relations
+--------+------------+-------------------+-------+---------+-------------+
| Schema |    Name    |       Type        | Owner |  Size   | Description |
+--------+------------+-------------------+-------+---------+-------------+
| public | data       | partitioned table | pavel | 0 bytes |             |
| public | data_2016  | table             | pavel | 15 MB   |             |
| public | data_2017  | table             | pavel | 15 MB   |             |
| public | data_other | table             | pavel | 11 MB   |             |
+--------+------------+-------------------+-------+---------+-------------+
(4 rows)

A patch is simple for this case

diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index c3bdf8555d..491e58eb29 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -3490,8 +3490,8 @@ listTables(const char *tabtypes, const char *pattern,
bool verbose, bool showSys
gettext_noop("sequence"),
gettext_noop("special"),
gettext_noop("foreign table"),
-                     gettext_noop("table"),    /* partitioned table */
-                     gettext_noop("index"),    /* partitioned index */
+                     gettext_noop("partitioned table"),    /* partitioned
table */
+                     gettext_noop("partitioned index"),    /* partitioned
index */
gettext_noop("Type"),
gettext_noop("Owner"));

Inclined to +1 this, too. Although, one might ask why partitioned tables
are called so only in the psql's output, but not in the backend's error
messages, for example, as was discussed in the past.

Thanks,
Amit

#13Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#12)
Re: ToDo: show size of partitioned table

2018-07-25 11:09 GMT+02:00 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>:

Hi Pavel.

On 2018/07/23 20:46, Pavel Stehule wrote:

Hi

I am sending a prototype of patch. Now, it calculates size of partitioned
tables with recursive query. When any more simple method will be

possible,

the size calculation will be changed.

postgres=# \dt+
List of relations
+--------+------------+-------+-------+---------+-------------+
| Schema |    Name    | Type  | Owner |  Size   | Description |
+--------+------------+-------+-------+---------+-------------+
| public | data       | table | pavel | 0 bytes |             |
| public | data_2016  | table | pavel | 15 MB   |             |
| public | data_2017  | table | pavel | 15 MB   |             |
| public | data_other | table | pavel | 11 MB   |             |
+--------+------------+-------+-------+---------+-------------+
(4 rows)
postgres=# \dP+
List of partitioned tables
+--------+------+-------+-------+-------------+
| Schema | Name | Owner | Size  | Description |
+--------+------+-------+-------+-------------+
| public | data | pavel | 42 MB |             |
+--------+------+-------+-------+-------------+
(1 row)

This looks nice, although I haven't looked at the patch yet. Also, as you
said, we could later replace the method of directly querying pg_inherits
by something else.

p.s. Another patch can be replacement of relation type from "table" to
"partitioned table"

postgres=# \dt+
List of relations
+--------+------------+-------------------+-------+---------

+-------------+

| Schema | Name | Type | Owner | Size |

Description |

+--------+------------+-------------------+-------+---------

+-------------+

| public | data | partitioned table | pavel | 0 bytes |

|

| public | data_2016 | table | pavel | 15 MB |

|

| public | data_2017 | table | pavel | 15 MB |

|

| public | data_other | table | pavel | 11 MB |

|

+--------+------------+-------------------+-------+---------

+-------------+

(4 rows)

A patch is simple for this case

diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index c3bdf8555d..491e58eb29 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -3490,8 +3490,8 @@ listTables(const char *tabtypes, const char

*pattern,

bool verbose, bool showSys
gettext_noop("sequence"),
gettext_noop("special"),
gettext_noop("foreign table"),
-                     gettext_noop("table"),    /* partitioned table */
-                     gettext_noop("index"),    /* partitioned index */
+                     gettext_noop("partitioned table"),    /*

partitioned

table */
+ gettext_noop("partitioned index"), /*

partitioned

index */
gettext_noop("Type"),
gettext_noop("Owner"));

Inclined to +1 this, too. Although, one might ask why partitioned tables
are called so only in the psql's output, but not in the backend's error
messages, for example, as was discussed in the past.

i think so error messages is different chapter - it means revision of all
error messages, and probably somewhere the name of partition, and not
partition table can be correct.

Personally I am not sure about benefit to change error messages. Now, the
partition is table too, so the error messages are not strongly wrong.

Regards

Pavel

Show quoted text

Thanks,
Amit

#14Mathias Brossard
postgresql@zoinx.org
In reply to: Pavel Stehule (#13)
Re: ToDo: show size of partitioned table

The following review has been posted through the commitfest application:
make installcheck-world: tested, failed
Implements feature: tested, passed
Spec compliant: not tested
Documentation: tested, passed

Hi,

I'm with Melanie Plageman running the SVPUG Patch Review Meetup. I tested this feature on my Mac. The patch applied cleanly on master, and the feature worked as expected with the SQL at the bottom of this email (Jesse Zhang suggested the two-level partitioning). installcheck passed but installcheck-world did not.

I do have a feedback on the implementation. The code tries to support older PostgreSQL server versions when declarative partitions were not supported before version 10 (relkind value of 'p'). Those versions will never return any result from the query being built. So I would suggest an early return from the function. The upside would be that the query building would be simpler. I can make patch implementing that suggestion if you want.

Sincerely,
-- Mathias Brossard

CREATE TABLE partition (
part int not null,
value int not null
) PARTITION BY RANGE (part);

CREATE TABLE partition_0 PARTITION OF partition FOR VALUES FROM (0) TO (10);
CREATE TABLE partition_1 PARTITION OF partition FOR VALUES FROM (10) TO (20);
CREATE TABLE partition_2 PARTITION OF partition FOR VALUES FROM (20) TO (30);
CREATE TABLE partition_3 PARTITION OF partition FOR VALUES FROM (30) TO (40);
CREATE TABLE partition_4 PARTITION OF partition FOR VALUES FROM (40) TO (50);
CREATE TABLE partition_5 PARTITION OF partition FOR VALUES FROM (50) TO (60);
CREATE TABLE partition_6 PARTITION OF partition FOR VALUES FROM (60) TO (70);
CREATE TABLE partition_7 PARTITION OF partition FOR VALUES FROM (70) TO (80);
CREATE TABLE partition_8 PARTITION OF partition FOR VALUES FROM (80) TO (90);
CREATE TABLE partition_9 (
part int not null,
value int not null
) PARTITION BY RANGE (part);

CREATE TABLE partition_9a PARTITION OF partition_9 FOR VALUES FROM (90) TO (95);
CREATE TABLE partition_9b PARTITION OF partition_9 FOR VALUES FROM (95) TO (100);
ALTER TABLE partition ATTACH PARTITION partition_9 FOR VALUES FROM (90) TO (100);

INSERT INTO partition SELECT i % 100 AS part, i AS value FROM generate_series(1, 1000000) AS i;

-------------------
-- Below is the resulting output

test=# \dt+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+--------------+-------+-----------+---------+-------------
public | partition | table | mbrossard | 0 bytes |
public | partition_0 | table | mbrossard | 3568 kB |
public | partition_1 | table | mbrossard | 3568 kB |
public | partition_2 | table | mbrossard | 3568 kB |
public | partition_3 | table | mbrossard | 3568 kB |
public | partition_4 | table | mbrossard | 3568 kB |
public | partition_5 | table | mbrossard | 3568 kB |
public | partition_6 | table | mbrossard | 3568 kB |
public | partition_7 | table | mbrossard | 3568 kB |
public | partition_8 | table | mbrossard | 3568 kB |
public | partition_9 | table | mbrossard | 0 bytes |
public | partition_9a | table | mbrossard | 1800 kB |
public | partition_9b | table | mbrossard | 1800 kB |
(13 rows)

test=# \dP+
List of partitioned tables
Schema | Name | Owner | Size | Description
--------+-------------+-----------+---------+-------------
public | partition | mbrossard | 35 MB |
public | partition_9 | mbrossard | 3600 kB |
(2 rows)

test=# \dP+ *9
List of partitioned tables
Schema | Name | Owner | Size | Description
--------+-------------+-----------+---------+-------------
public | partition_9 | mbrossard | 3600 kB |
(1 row)

#15Pavel Stehule
pavel.stehule@gmail.com
In reply to: Mathias Brossard (#14)
Re: ToDo: show size of partitioned table

Hi

čt 16. 8. 2018 v 5:52 odesílatel Mathias Brossard <postgresql@zoinx.org>
napsal:

The following review has been posted through the commitfest application:
make installcheck-world: tested, failed
Implements feature: tested, passed
Spec compliant: not tested
Documentation: tested, passed

Hi,

I'm with Melanie Plageman running the SVPUG Patch Review Meetup. I tested
this feature on my Mac. The patch applied cleanly on master, and the
feature worked as expected with the SQL at the bottom of this email (Jesse
Zhang suggested the two-level partitioning). installcheck passed but
installcheck-world did not.

I do have a feedback on the implementation. The code tries to support
older PostgreSQL server versions when declarative partitions were not
supported before version 10 (relkind value of 'p'). Those versions will
never return any result from the query being built. So I would suggest an
early return from the function. The upside would be that the query building
would be simpler. I can make patch implementing that suggestion if you want.

This is question - maybe we can support older partitioning based on only
inheritance - and the query can be more exact on PostgreSQL 10 and newer.

Please, send any patch. You are welcome.

Regards

Pavel

Show quoted text

Sincerely,
-- Mathias Brossard

CREATE TABLE partition (
part int not null,
value int not null
) PARTITION BY RANGE (part);

CREATE TABLE partition_0 PARTITION OF partition FOR VALUES FROM (0) TO
(10);
CREATE TABLE partition_1 PARTITION OF partition FOR VALUES FROM (10) TO
(20);
CREATE TABLE partition_2 PARTITION OF partition FOR VALUES FROM (20) TO
(30);
CREATE TABLE partition_3 PARTITION OF partition FOR VALUES FROM (30) TO
(40);
CREATE TABLE partition_4 PARTITION OF partition FOR VALUES FROM (40) TO
(50);
CREATE TABLE partition_5 PARTITION OF partition FOR VALUES FROM (50) TO
(60);
CREATE TABLE partition_6 PARTITION OF partition FOR VALUES FROM (60) TO
(70);
CREATE TABLE partition_7 PARTITION OF partition FOR VALUES FROM (70) TO
(80);
CREATE TABLE partition_8 PARTITION OF partition FOR VALUES FROM (80) TO
(90);
CREATE TABLE partition_9 (
part int not null,
value int not null
) PARTITION BY RANGE (part);

CREATE TABLE partition_9a PARTITION OF partition_9 FOR VALUES FROM (90) TO
(95);
CREATE TABLE partition_9b PARTITION OF partition_9 FOR VALUES FROM (95) TO
(100);
ALTER TABLE partition ATTACH PARTITION partition_9 FOR VALUES FROM (90) TO
(100);

INSERT INTO partition SELECT i % 100 AS part, i AS value FROM
generate_series(1, 1000000) AS i;

-------------------
-- Below is the resulting output

test=# \dt+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+--------------+-------+-----------+---------+-------------
public | partition | table | mbrossard | 0 bytes |
public | partition_0 | table | mbrossard | 3568 kB |
public | partition_1 | table | mbrossard | 3568 kB |
public | partition_2 | table | mbrossard | 3568 kB |
public | partition_3 | table | mbrossard | 3568 kB |
public | partition_4 | table | mbrossard | 3568 kB |
public | partition_5 | table | mbrossard | 3568 kB |
public | partition_6 | table | mbrossard | 3568 kB |
public | partition_7 | table | mbrossard | 3568 kB |
public | partition_8 | table | mbrossard | 3568 kB |
public | partition_9 | table | mbrossard | 0 bytes |
public | partition_9a | table | mbrossard | 1800 kB |
public | partition_9b | table | mbrossard | 1800 kB |
(13 rows)

test=# \dP+
List of partitioned tables
Schema | Name | Owner | Size | Description
--------+-------------+-----------+---------+-------------
public | partition | mbrossard | 35 MB |
public | partition_9 | mbrossard | 3600 kB |
(2 rows)

test=# \dP+ *9
List of partitioned tables
Schema | Name | Owner | Size | Description
--------+-------------+-----------+---------+-------------
public | partition_9 | mbrossard | 3600 kB |
(1 row)

#16Mathias Brossard
mathias@brossard.org
In reply to: Pavel Stehule (#15)
Re: ToDo: show size of partitioned table

On Thu, Aug 16, 2018 at 12:46 AM Pavel Stehule <pavel.stehule@gmail.com>
wrote:

čt 16. 8. 2018 v 5:52 odesílatel Mathias Brossard <postgresql@zoinx.org>
napsal:

I do have a feedback on the implementation. The code tries to support
older PostgreSQL server versions when declarative partitions were not
supported before version 10 (relkind value of 'p'). Those versions will
never return any result from the query being built. So I would suggest an
early return from the function. The upside would be that the query building
would be simpler. I can make patch implementing that suggestion if you want.

This is question - maybe we can support older partitioning based on only
inheritance - and the query can be more exact on PostgreSQL 10 and newer.

Please, send any patch. You are welcome.

In my very humble opinion, I would restrict the definition of partitions to
declarative partitioning. My justification would be that partitions all use
inheritance, but not all inheritance is a partition (how would you handle
multiple inheritance).

See patch attached that fails (in a way similar to other features) when
connected to servers with version earlier than 10.0.

Sincerely,
-- Mathias Brossard

Attachments:

psql-dP-10+only.patchapplication/octet-stream; name=psql-dP-10+only.patchDownload+136-2
#17Michael Paquier
michael@paquier.xyz
In reply to: Amit Langote (#12)
Re: ToDo: show size of partitioned table

On Wed, Jul 25, 2018 at 06:09:05PM +0900, Amit Langote wrote:

This looks nice, although I haven't looked at the patch yet. Also, as you
said, we could later replace the method of directly querying pg_inherits
by something else.

Yes, at the end we may be looking at something like that which would
avoid the need of any WITH RECURSIVE queries:
https://commitfest.postgresql.org/19/1694/

Tha patch still applies, but I think that we'd want to do something for
the partition tree function first, and then come to this one. Moved to
next CF.
--
Michael

#18Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Mathias Brossard (#16)
Re: ToDo: show size of partitioned table

Hi Mathias, Pavel,

On 2018/08/17 12:26, Mathias Brossard wrote:

On Thu, Aug 16, 2018 at 12:46 AM Pavel Stehule <pavel.stehule@gmail.com>

This is question - maybe we can support older partitioning based on only
inheritance - and the query can be more exact on PostgreSQL 10 and newer.

Please, send any patch. You are welcome.

In my very humble opinion, I would restrict the definition of partitions to
declarative partitioning. My justification would be that partitions all use
inheritance, but not all inheritance is a partition (how would you handle
multiple inheritance).

See patch attached that fails (in a way similar to other features) when
connected to servers with version earlier than 10.0.

The patch to add the pg_partition_tree() function was just committed:

Add pg_partition_tree to display information about partitions
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=d5eec4eefde70

Could one of you please revise the patch to use that function to produce
the output of \dP+?

Note that pg_partition_tree simply scans the underlying catalog to get all
the tables, so if you pass it a table that's not partitioned (relkind ==
'r'), but has inheritance children, the children will be returned in its
output. So, if you want to limit the output of \dP to partitioned tables,
be sure to include relkind = 'p' condition in the query.

Thanks,
Amit

#19Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#18)
Re: ToDo: show size of partitioned table

Hi

út 30. 10. 2018 v 7:52 odesílatel Amit Langote <
Langote_Amit_f8@lab.ntt.co.jp> napsal:

Hi Mathias, Pavel,

On 2018/08/17 12:26, Mathias Brossard wrote:

On Thu, Aug 16, 2018 at 12:46 AM Pavel Stehule <pavel.stehule@gmail.com>

This is question - maybe we can support older partitioning based on only
inheritance - and the query can be more exact on PostgreSQL 10 and

newer.

Please, send any patch. You are welcome.

In my very humble opinion, I would restrict the definition of partitions

to

declarative partitioning. My justification would be that partitions all

use

inheritance, but not all inheritance is a partition (how would you handle
multiple inheritance).

See patch attached that fails (in a way similar to other features) when
connected to servers with version earlier than 10.0.

The patch to add the pg_partition_tree() function was just committed:

Add pg_partition_tree to display information about partitions

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=d5eec4eefde70

Could one of you please revise the patch to use that function to produce
the output of \dP+?

here it is.

It is based on Mathias's patch. Although we can use pg_partition_tree on
PostgreSQL, we still should to support PostgreSQL 10, 11 where this
function is not available

Regards

Pavel

Show quoted text

Note that pg_partition_tree simply scans the underlying catalog to get all
the tables, so if you pass it a table that's not partitioned (relkind ==
'r'), but has inheritance children, the children will be returned in its
output. So, if you want to limit the output of \dP to partitioned tables,
be sure to include relkind = 'p' condition in the query.

Thanks,
Amit

Attachments:

psql-dP-2.patchtext/x-patch; charset=US-ASCII; name=psql-dP-2.patchDownload+150-2
#20Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#19)
Re: ToDo: show size of partitioned table

On Tue, Oct 30, 2018 at 8:04 PM Pavel Stehule <pavel.stehule@gmail.com> wrote:

út 30. 10. 2018 v 7:52 odesílatel Amit Langote <Langote_Amit_f8@lab.ntt.co.jp> napsal:

The patch to add the pg_partition_tree() function was just committed:

Add pg_partition_tree to display information about partitions
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=d5eec4eefde70

Could one of you please revise the patch to use that function to produce
the output of \dP+?

here it is.

It is based on Mathias's patch. Although we can use pg_partition_tree on PostgreSQL, we still should to support PostgreSQL 10, 11 where this function is not available

Ah, I forgot that psql will need to consider 10 and 11 servers too.

Thanks,
Amit

#21Michael Paquier
michael@paquier.xyz
In reply to: Amit Langote (#20)
#22Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#19)
#23Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#22)
#24Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#23)
#25Michael Paquier
michael@paquier.xyz
In reply to: Amit Langote (#24)
#26Pavel Stehule
pavel.stehule@gmail.com
In reply to: Michael Paquier (#25)
#27Michael Paquier
michael@paquier.xyz
In reply to: Pavel Stehule (#26)
#28Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#24)
#29Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#28)
#30Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#29)
#31Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#30)
#32Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#31)
#33Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#11)
#34Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Alvaro Herrera (#33)
#35Michael Paquier
michael@paquier.xyz
In reply to: Alvaro Herrera (#33)
#36Pavel Stehule
pavel.stehule@gmail.com
In reply to: Michael Paquier (#35)
#37Michael Paquier
michael@paquier.xyz
In reply to: Pavel Stehule (#36)
#38Michael Paquier
michael@paquier.xyz
In reply to: Pavel Stehule (#32)
#39Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Michael Paquier (#38)
#40Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#39)
#41Pavel Stehule
pavel.stehule@gmail.com
In reply to: Michael Paquier (#38)
#42Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#41)
#43Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#42)
#44Michael Paquier
michael@paquier.xyz
In reply to: Pavel Stehule (#43)
#45Pavel Stehule
pavel.stehule@gmail.com
In reply to: Michael Paquier (#44)
#46Michael Paquier
michael@paquier.xyz
In reply to: Pavel Stehule (#45)
#47Pavel Stehule
pavel.stehule@gmail.com
In reply to: Michael Paquier (#46)
#48Michael Paquier
michael@paquier.xyz
In reply to: Pavel Stehule (#47)
#49Pavel Stehule
pavel.stehule@gmail.com
In reply to: Michael Paquier (#48)
#50Pavel Stehule
pavel.stehule@gmail.com
In reply to: Pavel Stehule (#49)
#51Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#50)
#52Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#51)
#53Michael Paquier
michael@paquier.xyz
In reply to: Pavel Stehule (#52)
#54Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#52)
#55Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#54)
#56Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#55)
#57Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#56)
#58Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#57)
#59Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#58)
#60Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#54)
#61Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#60)
#62Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#61)
#63Justin Pryzby
pryzby@telsasoft.com
In reply to: Pavel Stehule (#62)
#64Pavel Stehule
pavel.stehule@gmail.com
In reply to: Justin Pryzby (#63)
#65Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#64)
#66Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#65)
#67Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#66)
#68David Steele
david@pgmasters.net
In reply to: Amit Langote (#67)
#69Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: David Steele (#68)
#70Peter Eisentraut
peter_e@gmx.net
In reply to: Amit Langote (#69)
#71Pavel Stehule
pavel.stehule@gmail.com
In reply to: Peter Eisentraut (#70)
#72Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Peter Eisentraut (#70)
#73Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Amit Langote (#72)
#74Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Amit Langote (#65)
#75Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#74)
#76Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#75)
#77Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Alvaro Herrera (#76)
#78Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Amit Langote (#77)
#79Kyotaro Horiguchi
horikyota.ntt@gmail.com
In reply to: Alvaro Herrera (#78)
#80Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Kyotaro Horiguchi (#79)
#81Kyotaro Horiguchi
horikyota.ntt@gmail.com
In reply to: Amit Langote (#80)
#82Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Kyotaro Horiguchi (#81)
#83Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#82)
#84Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Alvaro Herrera (#82)
#85Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Amit Langote (#84)
#86Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#85)
#87Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#86)
#88Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#87)
#89Justin Pryzby
pryzby@telsasoft.com
In reply to: Alvaro Herrera (#88)
#90Pavel Stehule
pavel.stehule@gmail.com
In reply to: Justin Pryzby (#89)
#91Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#88)
#92Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#90)
#93Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#92)
#94Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#92)
#95Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#94)
#96Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#95)
#97Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#96)
#98Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#97)
#99Justin Pryzby
pryzby@telsasoft.com
In reply to: Alvaro Herrera (#98)
#100Justin Pryzby
pryzby@telsasoft.com
In reply to: Justin Pryzby (#99)
#101Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#98)
#102Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#101)
#103Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Amit Langote (#102)
#104Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Alvaro Herrera (#103)
#105Justin Pryzby
pryzby@telsasoft.com
In reply to: Justin Pryzby (#100)
#106Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Justin Pryzby (#105)