pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Are indices used for creating check constraints?
2+ messages / 2 participants
[nested] [flat]

* Are indices used for creating check constraints?
@ 2018-10-22 17:55  Dinko Papak <rimokatolik@outlook.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Dinko Papak @ 2018-10-22 17:55 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Here are 3 interesting (to me) numbers:

1. creating index on expression (func(timestamp)) takes 5 seconds

2. creating check constraint on the same expression takes 10 seconds

3. adding partition table based on the same expression without check expression takes 20 seconds (this has been resolved by answer from David Rowley)


I tried various kind of indices to optimize 2. but nothing helps. When creating check constraint on column values directly is very fast (seems analyze helps), but creating check constraint on expression is very slow, even twice as long as creating index on the same expression.


Is it possible to use indices to create check expressions?

Why is 2. twice as long as 1.?

Why is 3. twice as long as 2.? (when there is no appropriate check constraint for 3.)


Thank you,

Dinko


Sent from Outlook<http://aka.ms/weboutlook;

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Are indices used for creating check constraints?
@ 2018-10-22 18:12  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Dinko Papak <rimokatolik@outlook.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2018-10-22 18:12 UTC (permalink / raw)
  To: Dinko Papak <rimokatolik@outlook.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Dinko Papak <rimokatolik@outlook.com> writes:
> Here are 3 interesting (to me) numbers:
> 1. creating index on expression (func(timestamp)) takes 5 seconds
> 2. creating check constraint on the same expression takes 10 seconds
> 3. adding partition table based on the same expression without check expression takes 20 seconds (this has been resolved by answer from David Rowley)

Hmm ...

> Is it possible to use indices to create check expressions?

No.

> Why is 2. twice as long as 1.?

Good question.  Could you provide a concrete test case?

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2018-10-22 18:12 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-10-22 17:55 Are indices used for creating check constraints? Dinko Papak <rimokatolik@outlook.com>
2018-10-22 18:12 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox