Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pEFzH-0005n1-Ro for pgsql-general@arkaria.postgresql.org; Sat, 07 Jan 2023 20:40:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pEFzG-0000wt-As for pgsql-general@arkaria.postgresql.org; Sat, 07 Jan 2023 20:40:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pEFzG-0000wk-0k for pgsql-general@lists.postgresql.org; Sat, 07 Jan 2023 20:40:18 +0000 Received: from mout-u-107.mailbox.org ([80.241.59.207]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pEFzC-0004rU-JV for pgsql-general@lists.postgresql.org; Sat, 07 Jan 2023 20:40:17 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4NqBsk5yX9z9stV; Sat, 7 Jan 2023 21:40:10 +0100 (CET) Date: Sat, 7 Jan 2023 21:40:09 +0100 (CET) From: Erik Wienhold To: Marc Millas , "pgsql-general@lists.postgresql.org" Message-ID: <832577793.126542.1673124009766@office.mailbox.org> In-Reply-To: References: Subject: Re: impact join syntax ?? and gist index ?? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Normal List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 07/01/2023 20:46 CET Marc Millas wrote: > > Hi, > > postgres 12, postgis 3.0 > > I have a small table A, 11 rows with a varchar column x and a geometry co= lumn y. > gist index=C2=A0on the geometry column. > the geometry do contains multipolygons (regions on a map) > I have a second table B , same structure, around 420 000 rows. > no index, > the geometry do contains points. > all geometries are on 4326 srid. > > If i ask to count points in each multipolygons: > > select A.x, count(B.x) from A, B where st_within(B.y, A.y) group by A.x; > it takes 11 seconds (everything in shared buffers). > If I do the very same thing as: > select A.x, count(B.x) from A left join B on st_within(B.y, A.y) group by= A.x; > same result, but 85 seconds (every thing in shared buffers, again) > if I redo asking with=C2=A0explain analyze, buffers, the plan is very dif= ferent. > > > if I do create a gist index on geometry column of the big table, both=C2= =A0syntax takes 21 seconds. > > I get=C2=A0the=C2=A0feeling I am missing something.. (at least 2 things..= .) > can someone shed some light ?? Please provide the executions plans for both queries with and without the i= ndex on B.y. -- Erik