Are indices used for creating check constraints?

From: Dinko Papak <rimokatolik(at)outlook(dot)com>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Are indices used for creating check constraints?
Date: 2018-10-22 17:55:56
Message-ID: CY4PR0101MB31750EF1C65CDC3680AF516DBAF40@CY4PR0101MB3175.prod.exchangelabs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2018-10-22 18:12:18 Re: Are indices used for creating check constraints?
Previous Message Andres Freund 2018-10-22 17:32:05 Re: Replication question