RE: alter table xxx alter column yyy set (n_distinct=nnnn );

Поиск
Список
Период
Сортировка
От Tefft, Michael J
Тема RE: alter table xxx alter column yyy set (n_distinct=nnnn );
Дата
Msg-id BN8PR04MB62894EF8DC3C2336F9801D1ED0242@BN8PR04MB6289.namprd04.prod.outlook.com
обсуждение исходный текст
Ответ на Re: alter table xxx alter column yyy set (n_distinct=nnnn );  (Greg Sabino Mullane <htamfids@gmail.com>)
Список pgsql-general

OK, thanks to both of you, it is now working for me. Many thanks.

 

This is what I determined was the missing ingredient from the secret sauce…

 

One of the things I had tried (before posting here) was

Alter table xxx alter column p_id set statistics [varying values];

 

Including zero.

 

When I first tried the suggestion of also setting n_distinct_inherited, these columns were still set to “statistics 0”.

 

When I altered them back to the default value i.e.

Alter table xxx alter column p_id set statistics -1;

(or, in fact, any nonzero value), the desired n_distinct values appeared after ANALYZE.

 

So, to set n_distinct for column col1 in a partitioned table sss.xxx:

  1. Make sure column col1 has “statistics” != 0
  2. alter table sss.xxx alter column p_id set (n_distinct_inherited=[desired_value] );
  3. analyze sss.xxx;
  4. verify with: select attname, n_distinct from pg_stats where schemaname='sss' and tablename='xxx' and attname = ‘col1’;

 

So setting n_distinct on the column at the parent/partitioned-table level is not relevant for this.

 

Thanks again.

 

Mike Tefft

 

 

 

 

From: Greg Sabino Mullane <htamfids@gmail.com>
Sent: Monday, March 11, 2024 12:23 PM
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: Tefft, Michael J <Michael.J.Tefft@snapon.com>; pgsql-general@lists.postgresql.org
Subject: Re: alter table xxx alter column yyy set (n_distinct=nnnn );

 

Works for me on Postgres 14 as well. Maybe you are looking at the wrong table? Might help to show the exact steps you typed in. ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍

Works for me on Postgres 14 as well. Maybe you are looking at the wrong table? Might help to show the exact steps you typed in.

 

 

В списке pgsql-general по дате отправления:

Предыдущее
От: Michał Kłeczek
Дата:
Сообщение: Re: Pgxs - How to reference another extension
Следующее
От: Lorusso Domenico
Дата:
Сообщение: merge with view