From: Andrus <kobruleht2@hot.ee>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Cc: Laurenz Albe <laurenz.albe@cybertec.at>
Subject: Re: Performance degradation if query returns no rows and column expression is used after upgrading to 12
Date: Wed, 8 Apr 2020 16:34:36 +0300
Message-ID: <A2E2572094D4434CAEB57C80085B22C7@dell2> (raw)
In-Reply-To: <CAFj8pRAcz0z9k52P3hsnbxd4meBn+HztLNJJh3rG8o0eAh4n7g@mail.gmail.com>
References: <B8B5CD76F8D1442B91F4DA690CA32E06@dell2>
<CAFj8pRC_MJcxc+1HOBNPaa+GgT4anPJ5xeO2sbitWS=owvpLPw@mail.gmail.com>
<7B5F7FA194F448E3A12E75BD81E3E946@dell2>
<CAFj8pRA9bk4_cYUj9=UWG-XyKfeRCawFD0j-BBRp0+4Z8u2Bjw@mail.gmail.com>
<4BAF2D141AF643C990BC5EFED45DD3AA@dell2>
<CAFj8pRAcz0z9k52P3hsnbxd4meBn+HztLNJJh3rG8o0eAh4n7g@mail.gmail.com>
Hi
>this query is little bit strange - it has pretty big cost, and because returns nothing, then it's pretty fast against cost.
>there is 18 subqueries, but jit_above_cost is ralated just to one query. This is probably worst case for JIT.
>This query is pretty slow and expensive (and then the cost of JIT is minimal), but when the query returns some rows, then JIT start to helps.
>So maybe if you find some queries that returns some rows, then the speed will be better with active JIT than with disabled JIT.
Below is modified testcase which returns one row.
In Debian 10 VPS with jit on it takes 2.5 sec and with jit off 0.4 s
jit is still many times slower in Debian even if data is returned.
In Windows 10 workstation there is no difference.
>The situation when the query returns no rows, then JIT is significant bottleneck - but it looks like corner case.
Both testcases simulate search queries in typical e-shop.
Users can use any search term and expect that query returns fast.
Modified testcase which returns one row:
create temp table toode ( toode char(20) primary key, ribakood char(20),
nimetus char(50), markused char(50), engnimetus char(50) ) on commit drop;
insert into toode (toode) select generate_series(1,14400);
insert into toode (toode,nimetus)
select 'TEST'|| generate_series, 'This is testmiin item'
from generate_series(1,1);
CREATE INDEX ON toode USING gin(to_tsvector('english'::regconfig, nimetus::text));
CREATE UNIQUE INDEX ON toode (ribakood )
WHERE ribakood IS NOT NULL AND btrim(ribakood::text) <> ''::text;
create temp table dok ( dokumnr serial primary key ) on commit drop;
insert into dok select generate_series(1,10000);
create temp table rid (id serial primary key,
dokumnr int references dok, taitmata numeric, toode char(20) references toode ) on commit drop;
insert into rid (dokumnr,toode)
select generate_series % 10000+1, 1
from generate_series(1,10000);
CREATE INDEX ON rid(dokumnr );
CREATE INDEX ON rid(toode);
-- jit on: 2.5 sec jit off: 0.4 s
set jit to off;
select
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode ) ,
(select sum(taitmata) from rid join dok using (dokumnr) where toode=toode.toode )
from toode
where toode.ribakood='testmiin'::text
or toode.nimetus ilike '%'||'testmiin'||'%' escape '!'
or toode.toode ilike '%'||'testmiin'||'%' escape '!'
or toode.markused ilike '%'||'testmiin'||'%' escape '!'
or to_tsvector('english',toode.nimetus) @@ plainto_tsquery('testmiin')
or to_tsvector('english',toode.engnimetus) @@
plainto_tsquery('testmiin')
Andrus.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: kobruleht2@hot.ee, pavel.stehule@gmail.com, laurenz.albe@cybertec.at
Subject: Re: Performance degradation if query returns no rows and column expression is used after upgrading to 12
In-Reply-To: <A2E2572094D4434CAEB57C80085B22C7@dell2>
References: <B8B5CD76F8D1442B91F4DA690CA32E06@dell2> <CAFj8pRC_MJcxc+1HOBNPaa+GgT4anPJ5xeO2sbitWS=owvpLPw@mail.gmail.com> <7B5F7FA194F448E3A12E75BD81E3E946@dell2> <CAFj8pRA9bk4_cYUj9=UWG-XyKfeRCawFD0j-BBRp0+4Z8u2Bjw@mail.gmail.com> <4BAF2D141AF643C990BC5EFED45DD3AA@dell2> <CAFj8pRAcz0z9k52P3hsnbxd4meBn+HztLNJJh3rG8o0eAh4n7g@mail.gmail.com> <A2E2572094D4434CAEB57C80085B22C7@dell2>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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