Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEegk-0003nQ-9K for pgsql-general@arkaria.postgresql.org; Mon, 22 Oct 2018 18:12:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gEegg-0004Bw-JB for pgsql-general@arkaria.postgresql.org; Mon, 22 Oct 2018 18:12:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEegg-0004Bc-7P for pgsql-general@lists.postgresql.org; Mon, 22 Oct 2018 18:12:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEegd-0007Gj-NH for pgsql-general@lists.postgresql.org; Mon, 22 Oct 2018 18:12:20 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w9MICILV010575; Mon, 22 Oct 2018 14:12:18 -0400 From: Tom Lane To: Dinko Papak cc: "pgsql-general@lists.postgresql.org" Subject: Re: Are indices used for creating check constraints? In-reply-to: References: Comments: In-reply-to Dinko Papak message dated "Mon, 22 Oct 2018 17:55:56 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <83721.1540231938.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 22 Oct 2018 14:12:18 -0400 Message-ID: <83722.1540231938@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Dinko Papak 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 exp= ression takes 20 seconds (this has been resolved by answer from David Rowl= ey) 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