Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1djsEV-0006Zk-Ck for pgsql-performance@arkaria.postgresql.org; Mon, 21 Aug 2017 19:19:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1djsET-0004oo-Rz for pgsql-performance@arkaria.postgresql.org; Mon, 21 Aug 2017 19:19:29 +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 1djsET-0004oe-BI for pgsql-performance@postgresql.org; Mon, 21 Aug 2017 19:19:29 +0000 Received: from mail-oi0-x235.google.com ([2607:f8b0:4003:c06::235]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1djsEM-0006FI-3g for pgsql-performance@postgresql.org; Mon, 21 Aug 2017 19:19:28 +0000 Received: by mail-oi0-x235.google.com with SMTP id r200so28804414oie.2 for ; Mon, 21 Aug 2017 12:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=LT9jjhf7bGbM7dqiE7q2XdnfR3uZw3nltE3VZT1H4IU=; b=ZisxsBo1xSviuGUf8hCFWEURCTZmMK4H1LASPC9+PHUhquRQPBnHdpM7LF2iWpytfa PHBIlTUo28zwYW3Vf6qEt9ZSX/lU7b0eJXKRN9rSGeKKLTdNCIYjUqbcXvZM14cWtb1o ih3e+rnIDb09Qr2MCN40BhwApYyiCqDD/5EpFmbyR7M2kxZir1nlT8ExJKgGAHrTdrqK tUjEwrOg1OGKY2GCehwl5G8QUiCXFFVrVAn25H5lJh3K8JSO/nPe5xikDCOaO0vLp4HT hPpM3WqCLgCQv3feueZSWDEdKaiE4DeQPd3BVxtd4rj/TSeAPsC6ZwOUtnylsZ0HotUr uM1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=LT9jjhf7bGbM7dqiE7q2XdnfR3uZw3nltE3VZT1H4IU=; b=niZ/zEbhHcDNQOzg5FvSvwblZ7oEzRHQznqBJBa7sXMcPiEb+v3s22xZYnWJlRJ+b5 /nzol5Ji5GWQzkCMytKkdHofsu4OabpHfEwDdk3Wj8a5sc7u8wJlTGy1IptgjLjAivm2 l4Hp7pfCsQKsnuABWxDx00CkB2eyTVDlwo9PG5nOgVwvDL97acx6kb2Ncr4Y4T2E7og3 r/FLoCbJd9GP+WmtRsE9UMC+XTZ3ZIebpX7CHB4OlHTvYWQxXPtB4sUXsaJ+7gm5qvc0 7T/M4wFSZGe1cVAgB1OknAERYliwsikW9U7P9w8mQrCuaqvZngj7S0p4TjR+hiRArxo5 7Y0A== X-Gm-Message-State: AHYfb5jSsFEhmbDfyEeMjruKTCpUhfwQbTBeeKwA7/uk9TjHovMAQukk T7m4pL63DqNr0zS8eugkUj4uqdtaJw== X-Received: by 10.202.204.212 with SMTP id c203mr1009831oig.11.1503343160828; Mon, 21 Aug 2017 12:19:20 -0700 (PDT) MIME-Version: 1.0 References: <1503164276875-5979128.post@n3.nabble.com> <20170821183226.GW24376@telsasoft.com> In-Reply-To: From: Carlos Augusto Machado Date: Mon, 21 Aug 2017 19:19:10 +0000 Message-ID: Subject: Re: Performance Issue -- "Materialize" To: pgsql-performance@postgresql.org Content-Type: multipart/alternative; boundary="001a1134f72e13a7eb0557485b17" 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 --001a1134f72e13a7eb0557485b17 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I think you query is a bit confusing and have many subqueries, so I tried to simplify If you cant=C2=B4t have more import_num =3D 0 to the same login, try this SELECT count(*) FROM test_tab tab1 LEFT JOIN test_tab tab2 ON tab1.login =3D tab2.login AND tab2.import_num =3D '0' WHERE tab2.login IS NULL AND import_num =3D '4520440' otherwise try this SELECT count(*) FROM test_tab tab1 LEFT JOIN ( SELECT DISTINCT login FROM test_tab WHERE import_num =3D '0' ) tab2 ON tab1.login =3D tab2.login WHERE tab2.login IS NULL AND import_num =3D '4520440' Em seg, 21 de ago de 2017 =C3=A0s 15:47, Carlos Augusto Machado < caugustom@gmail.com> escreveu: > > Do you have an index on login column ? > > If not, try creating an index and taking off those DISTICTs. > > Em seg, 21 de ago de 2017 =C3=A0s 15:33, Justin Pryzby > escreveu: > >> On Sat, Aug 19, 2017 at 10:37:56AM -0700, anand086 wrote: >> > >> +-----------------------------------------------------------------------= ---------------------------------------------------------------------------= ---------+| >> > QUERY PLAN >> > >> |+----------------------------------------------------------------------= ---------------------------------------------------------------------------= ----------+| >> > Aggregate (cost=3D351405.08..351405.09 rows=3D1 width=3D8) >> >> Would you send explain ANALYZE and not just explain ? >> >> Justin >> >> >> -- >> Sent via pgsql-performance mailing list (pgsql-performance@postgresql.or= g >> ) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-performance >> > --001a1134f72e13a7eb0557485b17 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

I think you query is a bit confusing a= nd have many subqueries, so I tried to simplify

If= you cant=C2=B4t have more import_num =3D 0 to the same login, try this

SELECT count(*)
FROM test_tab tab1
LEFT JOIN test_tab tab2
=C2=A0 =C2=A0 ON tab1.login =3D tab2.lo= gin AND tab2.import_num =3D '0'
WHERE=C2=A0
=C2= =A0 =C2=A0tab2.login IS NULL AND
=C2=A0 =C2=A0import_num =3D '= ;4520440'

otherwise try this

SELECT count(*)
FROM test_tab tab1
LEFT JOIN (<= /div>
=C2=A0 =C2=A0SELECT DISTINCT login FROM test_tab WHERE import_num= =3D '0'
) tab2
=C2=A0 =C2=A0 ON tab1.login =3D= tab2.login
WHERE=C2=A0
=C2=A0 =C2=A0tab2.login IS NULL= AND
=C2=A0 =C2=A0import_num =3D '4520440'

=

Em seg, 21 de ago de = 2017 =C3=A0s 15:47, Carlos Augusto Machado <caugustom@gmail.com> escreveu:

Do you have an index on login colum= n ?

If not, try creating an index and taking off t= hose DISTICTs.

E= m seg, 21 de ago de 2017 =C3=A0s 15:33, Justin Pryzby <pryzby@telsasoft.com> escre= veu:
On Sat, Aug 19, 2017 at 10:37:= 56AM -0700, anand086 wrote:
> +---------------------------------------------------------------------= ---------------------------------------------------------------------------= -----------+|
> QUERY PLAN
> |+--------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------+|
> Aggregate=C2=A0 (cost=3D351405.08..351405.09 rows=3D1 width=3D8)

Would you send explain ANALYZE and not just explain ?

Justin


--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-perform= ance
--001a1134f72e13a7eb0557485b17--