Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fY6Le-0004ce-Q7 for pgsql-performance@arkaria.postgresql.org; Wed, 27 Jun 2018 09:02:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fY6Lc-0002YF-NE for pgsql-performance@arkaria.postgresql.org; Wed, 27 Jun 2018 09:02:44 +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.89) (envelope-from ) id 1fY6Lc-0002Y8-FH for pgsql-performance@lists.postgresql.org; Wed, 27 Jun 2018 09:02:44 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fY6LZ-0004OW-Mh for pgsql-performance@postgresql.org; Wed, 27 Jun 2018 09:02:43 +0000 Received: by mail-wm0-x244.google.com with SMTP id l15-v6so17419874wmc.1 for ; Wed, 27 Jun 2018 02:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ad2games.com; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ug+hV6uYgXuqa6DUdpstHJLhhyPkC8pidWIp8Die5q0=; b=a6Y8ZX5XMiaCzIa8dikzr4tr7k/WsIUV2Ozj0OkldjxkOXrzKbBcUvWhTBI9trMMM5 jZzLT9purQtYesRtAXkzy318kFy1ZuYZF1G22XU6yHFGbC4+RTnwA2Antqmer+seceCr yW74zkKQyJHOzNECTVH8cZO6gPQpZZ+vK0BXo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ug+hV6uYgXuqa6DUdpstHJLhhyPkC8pidWIp8Die5q0=; b=PVq6o3ChLdvBm4dxAfaOCX0kfOXjWv3iObeCPNdnhcEUhyHJjhBPNxY0fSxfU6VUOO y+PhLsAHhfGtRp+dHUc5xVAtxyBS75FgY3cRdUOeqXv8ndQurbTJfREf4zUQ/tQZXS6v CrN5EKyi/PXfwQCrUrU7WxA5cWmdo0Mc4drOBFfslAjtvxJM6fQV8WiM67uNA1zHfNCe hObRowr4lUYnW+kFcFOd88IzHe037Pnb55FbdTWt5lMv0j9NdDXnaSaTwP856spVcs4X 9W8IJrpahCf8cHnN3C63JThoQwI55IBiFumvkcIB3pU98vO8qW3NWq3ch32bCqyOCz9T YqvA== X-Gm-Message-State: APt69E0e8uP6TBonEA48+VI6hwwktZ+js24BwCJVNawilcyxvHhete0O edviko27+Is06xbjBi2C7/Vg5ubwW4s= X-Google-Smtp-Source: AAOMgpcPlQEMWaEK53E3ZqRnkFfJnHn5sI7EHkMBozr0U6CX2aT25M6Uk5kmdkGwkmsZkKoMvDzctw== X-Received: by 2002:a1c:228b:: with SMTP id i133-v6mr4394989wmi.92.1530090160779; Wed, 27 Jun 2018 02:02:40 -0700 (PDT) Received: from [192.168.101.216] ([46.189.33.170]) by smtp.gmail.com with ESMTPSA id 13-v6sm6977387wmi.2.2018.06.27.02.02.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 02:02:39 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.4 \(3445.8.2\)) Subject: Re: Slow join From: Roman Kushnir In-Reply-To: <1530087558.2417.30.camel@cybertec.at> Date: Wed, 27 Jun 2018 11:02:38 +0200 Cc: pgsql-performance@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <5428CDF1-725B-4539-B569-4FD661664449@ad2games.com> References: <0B4D190F-CC48-4763-918D-4D4A8DAE5B0B@ad2games.com> <1530087558.2417.30.camel@cybertec.at> To: Laurenz Albe X-Mailer: Apple Mail (2.3445.8.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Laurenz, You=E2=80=99re right about the table being bloated, the = videos.description column is large. I thought about moving it to a = separate table, but having an index only on the columns used in the = query seems to have compensated for that already. Thank you. > On Jun 27, 2018, at 10:19 AM, Laurenz Albe = wrote: >=20 > Roman Kushnir wrote: >> The following basic inner join is taking too much time for me. (I=E2=80= =99m using count(videos.id) >> instead of count(*) because my actual query looks different, but I = simplified it here to the essence). >> I=E2=80=99ve tried following random people's suggestions and = adjusting the random_page_cost >> (decreasing it from 4 to 1.1) without a stable improvement. Any hints = on what is wrong here? Thank you. >>=20 >> The query >>=20 >> SELECT COUNT(videos.id) FROM videos JOIN accounts ON = accounts.channel_id =3D videos.channel_id; >>=20 >> The accounts table has 744 rows, videos table has 2.2M rows, the join = produces 135k rows. >>=20 >> Running on Amazon RDS, with default 10.1 parameters >>=20 >> version >> = --------------------------------------------------------------------------= ------------------------------- >> PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.2 = 20140120 (Red Hat 4.8.2-16), 64-bit >>=20 >> Execution plan https://explain.depesz.com/s/gf7 >=20 > Your time is spent here: >=20 >> -> Parallel Seq Scan on videos (cost=3D0.00..480898.90 rows=3D940390 = width=3D16) (actual time=3D0.687..55555.774 rows=3D764042 loops=3D3) >> Buffers: shared hit=3D7138 read=3D464357 >=20 > 55 seconds to scan 3.5 GB is not so bad. >=20 > What I wonder is how it is that you have less than two rows per table = block. > Could it be that the table is very bloated? >=20 > If you can, you could "VACUUM (FULL) videos" and see if that makes a = difference. > If you can bring the table size down, it will speed up query = performance. >=20 > Yours, > Laurenz Albe > --=20 > Cybertec | https://www.cybertec-postgresql.com