Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dS2Yi-00046S-DI for pgsql-bugs@arkaria.postgresql.org; Mon, 03 Jul 2017 14:42:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dS2Yh-0000ti-QC for pgsql-bugs@arkaria.postgresql.org; Mon, 03 Jul 2017 14:42:39 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dS2VG-0007UO-UT for pgsql-bugs@postgresql.org; Mon, 03 Jul 2017 14:39:07 +0000 Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dS2VD-0007cQ-H9 for pgsql-bugs@postgresql.org; Mon, 03 Jul 2017 14:39:05 +0000 Received: by mail-wm0-x230.google.com with SMTP id w126so170531499wme.0 for ; Mon, 03 Jul 2017 07:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=aRFVXPgmYVvPSRbsJGrGSTDjG0Q3Op6xiMcr2hTaSpc=; b=quYB7wCxtSUhYMM1qqn2amzgK+CEzAhOtCXd9WhiowRt9s8b2ISX976Dex0GYRseNH 775FiP7n7gMUA+sSZM/aXFFWq28iPJXP+wwBEAQvvbCOrMUNl+hHo1jnnosuZ1EX3I8p QwSiOTsht7UW1J4FAYc/RT/HSdL6Hm7k4U7n7fS6NkET6NkHP/NAfkQC9TcBGquBGxXM lBauSkQKAGdHd1lP+Q1QsHTtgxIKRkKwbX9BWib/PHJC5/L7/IgwvmUM6A9SeBs6FisW jBr+DFpV9ytPglwcrpya5nznOLMyqmFX7po7/9LfWxDXQQzBi93CWBmGLbvzirjWf1dt drLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=aRFVXPgmYVvPSRbsJGrGSTDjG0Q3Op6xiMcr2hTaSpc=; b=Gw2e4P40WrUcxn1zRJlvQJOdsH86ypunXCLcdnwcJe8CUou2g83IOHxSQe5Vh0xg1d oYggr56Trku5mYII/97+sCaWHtR+vQhxPQrG8rklDvx1WIAAdpwdHHl1D4OLuq5NBMpA U9bNZ+H54WaXS9B/4g/Wfbgk77NudgMf6sgiGjp26CiMQIPC4hT7hvx6KV0qcYvyBx6T i1BEY68oSNY1TORmGq24ggTAli9dvoqfRqL6KGfFxagYS+luvzX1YECzFYwhrdCxs2Sp 5x6LPV+ZglHSIzESHFahMeRijil/Uqhhy6cxJOQbaq/CGmKwp75zE854w+rNftJID7ng BXDg== X-Gm-Message-State: AKS2vOzdKo01hRQwH+slzOPUPszwhBzbcVdr5rCJKrI1YvwFqx2u/z5o pVm8sUmZmgoq/BwfqCI0UUkksDYuHw== X-Received: by 10.28.109.26 with SMTP id i26mr23555699wmc.64.1499092741767; Mon, 03 Jul 2017 07:39:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.175.12 with HTTP; Mon, 3 Jul 2017 07:39:01 -0700 (PDT) In-Reply-To: References: <20170703100923.1448.48433@wrigleys.postgresql.org> From: Pavel Tavoda Date: Mon, 3 Jul 2017 16:39:01 +0200 Message-ID: Subject: Re: BUG #14729: Between operator is slow when same value used for low and high margin To: Pavel Stehule Cc: "pgsql-bugs@postgresql.org" Content-Type: multipart/alternative; boundary="001a114677865bcb5205536aba41" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --001a114677865bcb5205536aba41 Content-Type: text/plain; charset="UTF-8" Hi Pavel, results down in text. On Mon, Jul 3, 2017 at 4:22 PM, Pavel Stehule wrote: > Hi > > 2017-07-03 12:09 GMT+02:00 : > >> SELECT count(*) FROM contractportfolio cp JOIN contract co ON cp.contract >> = >> co.id WHERE validfor between '2017-05-30' AND '2017-05-31'; >> Time: 0.473 >> > Aggregate (cost=110320.00..110320.01 rows=1 width=0) (actual time=520.304..520.304 rows=1 loops=1) -> Hash Join (cost=426.27..110244.02 rows=30393 width=0) (actual time=5.852..509.223 rows=40844 loops=1) Hash Cond: (cp.contract = co.id) -> Seq Scan on contractportfolio cp (cost=0.00..109171.90 rows=30393 width=8) (actual time=0.007..471.669 rows=40844 loops=1) Filter: ((validfor >= '2017-05-30'::date) AND (validfor <= '2017-05-31'::date)) Rows Removed by Filter: 2946433 -> Hash (cost=336.12..336.12 rows=7212 width=8) (actual time=5.833..5.833 rows=7198 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 197kB -> Seq Scan on contract co (cost=0.00..336.12 rows=7212 width=8) (actual time=0.006..2.856 rows=7198 loops=1) Planning time: 0.333 ms Execution time: 520.343 ms > SELECT count(*) FROM contractportfolio cp JOIN contract co ON cp.contract = >> co.id WHERE validfor between '2017-05-31' AND '2017-05-31'; >> Time: 19.172 >> > Aggregate (cost=109598.17..109598.18 rows=1 width=0) (actual time=87769.576..87769.577 rows=1 loops=1) -> Nested Loop (cost=0.00..109598.16 rows=1 width=0) (actual time=1.949..87759.415 rows=20426 loops=1) Join Filter: (cp.contract = co.id) Rows Removed by Join Filter: 147005922 -> Seq Scan on contractportfolio cp (cost=0.00..109171.90 rows=1 width=8) (actual time=0.009..486.918 rows=20426 loops=1) Filter: ((validfor >= '2017-05-31'::date) AND (validfor <= '2017-05-31'::date)) Rows Removed by Filter: 2966851 -> Seq Scan on contract co (cost=0.00..336.12 rows=7212 width=8) (actual time=0.001..2.046 rows=7198 loops=20426) Planning time: 0.319 ms Execution time: 87769.621 ms STUNNING!!!! > >> SELECT count(*) FROM contractportfolio cp JOIN contract co ON cp.contract >> = >> co.id WHERE validfor = '2017-05-31'; >> Time: 0.467 >> > Aggregate (cost=102402.86..102402.87 rows=1 width=0) (actual time=492.645..492.646 rows=1 loops=1) -> Hash Join (cost=426.27..102352.37 rows=20197 width=0) (actual time=5.873..486.873 rows=20426 loops=1) Hash Cond: (cp.contract = co.id) -> Seq Scan on contractportfolio cp (cost=0.00..101496.91 rows=20197 width=8) (actual time=0.009..463.063 rows=20426 loops=1) Filter: (validfor = '2017-05-31'::date) Rows Removed by Filter: 2966851 -> Hash (cost=336.12..336.12 rows=7212 width=8) (actual time=5.856..5.856 rows=7198 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 197kB -> Seq Scan on contract co (cost=0.00..336.12 rows=7212 width=8) (actual time=0.005..2.835 rows=7198 loops=1) Planning time: 0.325 ms Execution time: 492.686 ms --001a114677865bcb5205536aba41 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Pavel, results down in text.=

On Mon, Jul= 3, 2017 at 4:22 PM, Pavel Stehule <pavel.stehule@gmail.com><= /span> wrote:
Hi

20= 17-07-03 12:09 GMT+02:00 <pavel.tavoda@gmail.com>:
=
SELECT count(*) FROM cont= ractportfolio cp JOIN contract co ON cp.contract =3D
co.id WHE= RE validfor between '2017-05-30' AND '2017-05-31';
Time: 0.473
Aggreg= ate=C2=A0 (cost=3D110320.00..110320.01 rows=3D1 width=3D0) (actual time=3D5= 20.304..520.304 rows=3D1 loops=3D1)
=C2=A0 ->=C2=A0 Hash Join= =C2=A0 (cost=3D426.27..110244.02 rows=3D30393 width=3D0) (actual time=3D5.8= 52..509.223 rows=3D40844 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 H= ash Cond: (cp.contract =3D co.id)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Seq Scan on contractportfolio cp=C2= =A0 (cost=3D0.00..109171.90 rows=3D30393 width=3D8) (actual time=3D0.007..4= 71.669 rows=3D40844 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 Filter: ((validfor >=3D '2017-05-30'::date) AND (= validfor <=3D '2017-05-31'::date))
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Rows Removed by Filter: 2946433
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Hash=C2=A0 (cost=3D336.12..336.12 r= ows=3D7212 width=3D8) (actual time=3D5.833..5.833 rows=3D7198 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Buckets: 1024=C2= =A0 Batches: 1=C2=A0 Memory Usage: 197kB
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Seq Scan on contract co=C2=A0 (cost=3D= 0.00..336.12 rows=3D7212 width=3D8) (actual time=3D0.006..2.856 rows=3D7198= loops=3D1)
Planning time: 0.333 ms
Execution time: 520= .343 ms

=C2=A0
=C2=A0
SELECT count(*) FROM contractportfolio cp JOIN contract co ON cp.contract = =3D
co.id WHE= RE validfor between '2017-05-31' AND '2017-05-31';
Time: 19.172
Aggre= gate=C2=A0 (cost=3D109598.17..109598.18 rows=3D1 width=3D0) (actual time=3D= 87769.576..87769.577 rows=3D1 loops=3D1)
=C2=A0 ->=C2=A0 Neste= d Loop=C2=A0 (cost=3D0.00..109598.16 rows=3D1 width=3D0) (actual time=3D1.9= 49..87759.415 rows=3D20426 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0= Join Filter: (cp.contract =3D co.id)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Rows Removed by Join Filter: 147005922
<= div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Seq Scan on contractportfolio c= p=C2=A0 (cost=3D0.00..109171.90 rows=3D1 width=3D8) (actual time=3D0.009..4= 86.918 rows=3D20426 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 Filter: ((validfor >=3D '2017-05-31'::date) AND (= validfor <=3D '2017-05-31'::date))
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Rows Removed by Filter: 2966851
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Seq Scan on contract co=C2=A0 (cost= =3D0.00..336.12 rows=3D7212 width=3D8) (actual time=3D0.001..2.046 rows=3D7= 198 loops=3D20426)
Planning time: 0.319 ms
Execution ti= me: 87769.621 ms

STUNNING!!!!
=C2= =A0

SELECT count(*) FROM contractportfolio cp JOIN contract co ON cp.contract = =3D
co.id WHE= RE validfor =3D '2017-05-31';
Time: 0.467
Aggreg= ate=C2=A0 (cost=3D102402.86..102402.87 rows=3D1 width=3D0) (actual time=3D4= 92.645..492.646 rows=3D1 loops=3D1)
=C2=A0 ->=C2=A0 Hash Join= =C2=A0 (cost=3D426.27..102352.37 rows=3D20197 width=3D0) (actual time=3D5.8= 73..486.873 rows=3D20426 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 H= ash Cond: (cp.contract =3D co.id)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Seq Scan on contractportfolio cp=C2= =A0 (cost=3D0.00..101496.91 rows=3D20197 width=3D8) (actual time=3D0.009..4= 63.063 rows=3D20426 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 Filter: (validfor =3D '2017-05-31'::date)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Rows Removed by Filter: 29= 66851
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Hash=C2=A0 (cost=3D= 336.12..336.12 rows=3D7212 width=3D8) (actual time=3D5.856..5.856 rows=3D71= 98 loops=3D1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Bu= ckets: 1024=C2=A0 Batches: 1=C2=A0 Memory Usage: 197kB
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Seq Scan on contract co= =C2=A0 (cost=3D0.00..336.12 rows=3D7212 width=3D8) (actual time=3D0.005..2.= 835 rows=3D7198 loops=3D1)
Planning time: 0.325 ms
Exec= ution time: 492.686 ms

--001a114677865bcb5205536aba41--