Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ar06k-0005mg-TR for pgsql-performance@arkaria.postgresql.org; Fri, 15 Apr 2016 09:32:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ar06j-0004xt-Tw for pgsql-performance@arkaria.postgresql.org; Fri, 15 Apr 2016 09:32:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ar06j-0004xa-26 for pgsql-performance@postgresql.org; Fri, 15 Apr 2016 09:32:09 +0000 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1ar06f-0003D2-LC for pgsql-performance@postgresql.org; Fri, 15 Apr 2016 09:32:08 +0000 Received: by mail-wm0-x236.google.com with SMTP id n3so23823089wmn.0 for ; Fri, 15 Apr 2016 02:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=tEkFunycKyHjlj6uOAR0jm3h27B/1LAYF8Kh03vvURU=; b=R1dF6+LcBSvl6osN09O0ZFOHxcAF2fGgepf79zT5H6bGIkGrKhtvN4+qWCYg1w4PsX r1Q/HOT/aZ4+r6zsaAgvT+A0gmidJZZG9j9OHoq0fKO4t/sn7qw+Wqi+kk1BzEHIBrcI SFGqMp50spQOA4NYpwnoAsvmHyWYBsjonaecYhX7BwIXA9lYFipsN9FRkXBcTnw9yx+Q yJ2I7n/9+Px5JXmHvAsYN7urMezW8afTeSQtIzfekwi+8BcUBY9o77ZQTkNgdxN91jvS ZUYOJ4GHtcSQdOBAphd/tNceinpsk30lN/XQmGSioyHgTCQQG73bDcvlLT/QE5MDd2ax 2MWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=tEkFunycKyHjlj6uOAR0jm3h27B/1LAYF8Kh03vvURU=; b=kQ0U2n6lR6FR8p00udhuD32Nb/ldzTdmn6YYzVqA9A10Hzf/B7sEgjEuihWIB1b715 oOGJjKi27DZxd0KyKCKJXH5bt7LLW/JblSkCp9e92kIXWJNGspUZoH4fShSDgZiTDZ1O v7zFyQaYppmaGysH1ogmLpQCnoPc9MooPalBf5nnQOWk4g/b+lwFCcFH/QMZTHqCQ/ps 60SZa6Qeu5w4ahi/C8ga2CWIV3Ii8RPTMbKLhySlQt4GJjQlfj4sQfZpzipT2JVBxr8f 0MS4J+tnQ3gxWuNOcSdl1UIELAi9Ae33a5u9yU7y9qYpVXsVhkYRE7QGzWS2+pNeU5I8 BJRA== X-Gm-Message-State: AOPr4FWey912gsfyJT+4WyL2ch5uUK1FBNsvVlWnvSFf9QO2iWXiu4PT1dykG/UhQelxkw== X-Received: by 10.28.232.140 with SMTP id f12mr3386156wmi.6.1460712723732; Fri, 15 Apr 2016 02:32:03 -0700 (PDT) Received: from [192.168.1.2] ([37.44.88.247]) by smtp.gmail.com with ESMTPSA id cf6sm48169944wjc.12.2016.04.15.02.32.02 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Apr 2016 02:32:03 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: Slow update on column that is part of exclusion constraint From: Evgeniy Shishkin In-Reply-To: Date: Fri, 15 Apr 2016 12:31:59 +0300 Cc: pgsql-performance@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <5C918770-5BC7-43E2-90B1-9A90174370F6@gmail.com> To: Adam Brusselback X-Mailer: Apple Mail (2.3124) X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org > On 14 Apr 2016, at 07:17, Adam Brusselback wr= ote: >=20 > So fair enough, it does seem to be related to the lookup rather than main= tenance on the index. I was misguided in my initial assumption.=20=20 >=20 > Spent quite a bit of time trying to come up with a self contained test, a= nd it seems like I can't make it choose the GiST index unless I remove the = regular btree index in my test case, though the opposite is true for my tab= le in production. Not really sure what that means as far as what I need to= do though. I've tried a vacuum full, analyze, rebuild index, drop and re-a= dd the constraint... It still uses that GiST index for this query. >=20 > Hell, a sequential scan is a ton faster even. >=20 As i understand it, postgres needs a way to find rows for update. In explain analyze you provided, we see that it chose gist index for that. And that is a poor chose. I think you need a proper btree index for update= =20 query to work properly fast. Like index on (product_id, company_id, date_ra= nge) WHERE upper(price_generated_test.active_range) IS NULL.=20 > On Wed, Apr 13, 2016 at 2:54 PM, Evgeniy Shishkin = wrote: >=20 > > On 13 Apr 2016, at 20:14, Adam Brusselback = wrote: > > > > Sorry, brain stopped working and I forgot to include the normal info. > > > > Postgres version: 9.5.1 > > Hardware: 2 core, 4gb Digital Ocean virtual server > > OS: Debian > > > > explain analyze for an example update: > > 'Update on price_generated (cost=3D32.45..644.83 rows=3D1 width=3D157)= (actual time=3D29329.614..29329.614 rows=3D0 loops=3D1)' > > ' -> Nested Loop (cost=3D32.45..644.83 rows=3D1 width=3D157) (actual= time=3D29329.608..29329.608 rows=3D0 loops=3D1)' > > ' -> HashAggregate (cost=3D32.04..34.35 rows=3D231 width=3D52)= (actual time=3D1.137..2.090 rows=3D231 loops=3D1)' > > ' Group Key: pti.product_id, pti.company_id, pti.date_rang= e' > > ' -> Seq Scan on _prices_to_insert pti (cost=3D0.00..30.= 31 rows=3D231 width=3D52) (actual time=3D0.060..0.678 rows=3D231 loops=3D1)' > > ' -> Index Scan using price_generated_company_product_date_acti= ve_excl on price_generated (cost=3D0.41..2.63 rows=3D1 width=3D151) (actua= l time=3D126.949..126.949 rows=3D0 loops=3D231)' > > ' Index Cond: (date_range =3D pti.date_range)' > > ' Filter: ((upper(active_range) IS NULL) AND (pti.product_= id =3D product_id) AND (pti.company_id =3D company_id))' > > ' Rows Removed by Filter: 29460' > > 'Planning time: 3.134 ms' > > 'Execution time: 29406.717 ms' >=20 > Well, you see execution time of 30 seconds because there are 231 index lo= okups, > each taking 126 ms. >=20 > And that lookup is slow because of > Filter: ((upper(active_range) IS NULL) AND (pti.product_id =3D product_id= ) AND (pti.company_id =3D company_id))' >=20 > Can you provide self-containing example of update? > I don't see there (upper(active_range) IS NULL condition is coming from. >=20 > > --=20 > Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-performance --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance