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 1lJZ6Q-0002kV-LX for pgsql-general@arkaria.postgresql.org; Tue, 09 Mar 2021 09:56:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lJZ6P-0008KR-E8 for pgsql-general@arkaria.postgresql.org; Tue, 09 Mar 2021 09:56:33 +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 1lJZ6P-0008KJ-3q for pgsql-general@lists.postgresql.org; Tue, 09 Mar 2021 09:56:33 +0000 Received: from mail-eopbgr80083.outbound.protection.outlook.com ([40.107.8.83] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lJZ6M-0000l8-DU for pgsql-general@lists.postgresql.org; Tue, 09 Mar 2021 09:56:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wz4Ig7tcuaFlrsCzRtg+efQhI5+UNy7E/yEr5TkiGvOpZ+aQgnEjHbu7khXagsXfrDoMvMmQO2VeVt02W3B+yzdCHRN5utrUM/Pa4i4M41J1nGMvkZIxT4ytxR+eny1oaPghFtDsFKqqpLnJmZAW4DXPSwSMehZTibpBclCXUG78gKLkyasGD4+7BWY/ld2m9gl4W27Y+K9XIrB3Ziuc72yGB9BquazOpZuZlhIq+Z9zP8OH6JMaIj9yyviAG5M2TrJ1ozrTAX5JgOzo30WXDgqEYh+vo5R+zfh3rFzw0IjfIX66vItT8XuUKdss8RI4mLtpNpEMGMxikoNy1X8G9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n5A+tTmyIUESZ7SgfzcL5Cv8U2QyJrY/CDuzWSmCM40=; b=SY1l109REp94T76MT0n4UnKZ0WuAWOaoV1PJzcMCM8S72BxSLbcHzS5SGwlqpN2vlKDbmUt1iKNPHA/Z2/XHI/Wi+XVZA7E3gfVK8z57/WKiJuXTU0P66ITi2OQtN2D7GE69UHlcvRRBBnOTEEuG7VFmEFNr9cls5e5EG3Is4kWIIJsML6PEe4Vyg038vT4YF4mZVpmafDvaaNrJqmjA8EsMG+uSAtNKYJcsH541L7oaVas+jzyP35qbglbDBBOQ2x80yB/KACyWkjLjBshDPcFohy6TbIzjgfbky/GQUuZ7YM7DrZ9rsB2CNn3u97Byfhcxfo74FftJFU8AKfFbqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ucll.be; dmarc=pass action=none header.from=ucll.be; dkim=pass header.d=ucll.be; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucll.be; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n5A+tTmyIUESZ7SgfzcL5Cv8U2QyJrY/CDuzWSmCM40=; b=RMJe1BQYuBKA/S2JAUy+dr/21P2dMEq4Nhb3sQTXYhtDDWaW2d3YAQ0mQTbzQSKm3Prdfvzd4Xs/jhcCE0sT/Ic+PKFnHHbaDu5pJmxJHypqbldLEaakJvhLpRGuWPP8xWp8PLRE4VaegfdhYg/9OA/rVWCBusoT8OybLHi2NJY= Authentication-Results: lists.postgresql.org; dkim=none (message not signed) header.d=none;lists.postgresql.org; dmarc=none action=none header.from=ucll.be; Received: from AM9P195MB0790.EURP195.PROD.OUTLOOK.COM (2603:10a6:20b:1ff::22) by AM9P195MB0966.EURP195.PROD.OUTLOOK.COM (2603:10a6:20b:1cc::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19; Tue, 9 Mar 2021 09:56:27 +0000 Received: from AM9P195MB0790.EURP195.PROD.OUTLOOK.COM ([fe80::bdce:8f84:a8ec:26d1]) by AM9P195MB0790.EURP195.PROD.OUTLOOK.COM ([fe80::bdce:8f84:a8ec:26d1%3]) with mapi id 15.20.3912.027; Tue, 9 Mar 2021 09:56:27 +0000 Message-ID: Subject: curious cost vs execution time (local test) From: Wim Bertels Reply-To: wim.bertels@ucll.be To: pgsql-general@lists.postgresql.org Date: Tue, 09 Mar 2021 10:56:26 +0100 Organization: UC Leuven-Limburg Content-Type: multipart/alternative; boundary="=-jMZZM47WsG/85TSARXdV" User-Agent: Evolution 3.30.5-1.1 X-Originating-IP: [2a02:1811:526:1700:c626:fe0e:f5fc:d86a] X-ClientProxiedBy: AM0PR10CA0049.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::29) To AM9P195MB0790.EURP195.PROD.OUTLOOK.COM (2603:10a6:20b:1ff::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ptr-7u36h5n27jjeief2jxm.18120a2.ip6.access.telenet.be (2a02:1811:526:1700:c626:fe0e:f5fc:d86a) by AM0PR10CA0049.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Tue, 9 Mar 2021 09:56:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31dd49ec-bb60-4869-1369-08d8e2e19b59 X-MS-TrafficTypeDiagnostic: AM9P195MB0966: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:126; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dqHaLbWvewDh7A9TbOi2dEDJXlUjPAMJpT+hiWcN175w7kycXiOVt2qQvBYcryESa/XGmDPc3WWg1YFYn4ufZ0x8e7oITNJ08go9ssr9SB1qZyOwgZZ1rwYhOaeF/zNWLt5udxkur6YadX9e6qrUqOuNV05SUfUpNOm6Qbi8lgQXcDx29g2JErgYalpob8l7R5327fp2OAoo9WfTMjVBYok3SFYcsCETEerzgPmdCzc7+4EebSYCaeQRMD5k8amLnTvJpSdOc578qEXzCh/+nK7Nhd9VQDgnuQzw2v47keLIuaezImvFdHr67O8kqAPWNVC9TV1P5imfn1ZaW1cf0suxaFvAoNfClTLvsiFmMjb9w9Lt5cgzknHilFlQrQ3gVd7NM/FsrYVFi5E++B0g+XDxLJO0zyXXyeN421gVIZGR+0duGlZXB8vbik6GjBqqnZeG1cuoOwUewrBn5C38rbpaYb0C2UA0PdrKRY1eRZUrt2fs5RTME8q3HfSRW55jLBCiPa5jgl5CpnxHg5DjuVQzgQaNypWKuG21sLptPkU0CXh50yZkOk8uis1sjfdXHr3fpm/HtlTpqe0FIUbSnSddcI1FHPI50QYVAnvj//B+KiQZRsGmBIJRDSw675WwOcJO9gsT+pQS+hRDzbDqOQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9P195MB0790.EURP195.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(4636009)(366004)(396003)(346002)(39850400004)(136003)(376002)(316002)(66476007)(786003)(83380400001)(66946007)(966005)(33964004)(52116002)(36916002)(166002)(36756003)(44832011)(86362001)(6512007)(5660300002)(66556008)(8676002)(8936002)(2906002)(3450700001)(6506007)(478600001)(186003)(16526019)(6486002)(6916009)(2616005)(550174008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?YTViWE5YSUtDNkcrSndXUFFMVThWc2pES3ZJY3F0MUVpREVENkd3MFhUODdw?= =?utf-8?B?SElCM3llbzFwL3AzNWsrYjVmM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5cW1SMFZDRWlt?= =?utf-8?Q?972+OSyWy2NjT?= X-OriginatorOrg: ucll.be X-MS-Exchange-CrossTenant-Network-Message-Id: 31dd49ec-bb60-4869-1369-08d8e2e19b59 X-MS-Exchange-CrossTenant-AuthSource: AM9P195MB0790.EURP195.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2021 09:56:27.6482 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e638861b-15d9-4de6-a65d-b48789ae1f08 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: w8LXCSYMnwSI0B46/01Mir7I0FcFqUL7Pt/7AdfcUYdeoUP8dvtzkQJ1aZBeGBpkhCq9wIiveE9pYNf4zRH4IA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9P195MB0966 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-jMZZM47WsG/85TSARXdV Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Hello, Using the chinook database https://github.com/lerocha/chinook-database/blob/master/ChinookDatabase/DataSources/Chinook_PostgreSql.sql locally, so there should be little side-effects (network, host, cache..) for the following two equivalent queries, the cost and execution times are curious. (tip if you have problems on linux psql for the chinook database #set client_encoding to 'windows-1251'; ) Can anyone confirm or correct this? The equivalent queries are SELECT r1."Title",hs."Name",hs."Milliseconds" FROM "Album" r1 LEFT JOIN LATERAL (SELECT * FROM "Track" b2 natural inner join "Album" WHERE r1."AlbumId" = b2."AlbumId" ORDER BY "Milliseconds" desc FETCH FIRST 2 ROW ONLY) hs ON true; vs SELECT "Title", "Name", "Milliseconds" FROM "Album" A NATURAL INNER JOIN "Track" T WHERE 1 >= (SELECT COUNT(*) FROM "Album" NATURAL INNER JOIN "Track" WHERE "Album"."Title" = A."Title" AND "Track"."Milliseconds" < T."Milliseconds"); Running explain (analyze) a few times gives the following curious result: With the Lateral join query: QUERY PLAN --------------------------------------------------------------------- --------------------------------------------------------------------- ------------------ Nested Loop Left Join (cost=16.37..5701.03 rows=694 width=43) (actual time=0.043..7.347 rows=612 loops=1) -> Seq Scan on "Album" r1 (cost=0.00..6.47 rows=347 width=27) (actual time=0.006..0.022 rows=347 loops=1) -> Limit (cost=16.37..16.37 rows=2 width=856) (actual time=0.021..0.021 rows=2 loops=347) -> Sort (cost=16.37..16.39 rows=10 width=856) (actual time=0.021..0.021 rows=2 loops=347) Sort Key: b2."Milliseconds" DESC Sort Method: quicksort Memory: 25kB -> Nested Loop (cost=0.28..16.27 rows=10 width=856) (actual time=0.009..0.019 rows=10 loops=347) -> Seq Scan on "Album" (cost=0.00..7.34 rows=1 width=4) (actual time=0.008..0.016 rows=1 loops=347) Filter: ("AlbumId" = r1."AlbumId") Rows Removed by Filter: 346 -> Index Scan using "IFK_TrackAlbumId" on "Track" b2 (cost=0.28..8.83 rows=10 width=24) (actual time=0.001..0.002 rows=10 loops=347) Index Cond: ("AlbumId" = r1."AlbumId") Planning Time: 0.094 ms Execution Time: 7.388 ms With the correlated subquery (where): QUE RY PLAN --------------------------------------------------------------------- --------------------------------------------------------------------- --------- Hash Join (cost=10.81..148.79 rows=1168 width=43) (actual time=0.109..80.502 rows=612 loops=1) Hash Cond: (t."AlbumId" = a."AlbumId") Join Filter: (1 >= (SubPlan 1)) Rows Removed by Join Filter: 2891 -> Seq Scan on "Track" t (cost=0.00..80.03 rows=3503 width=24) (actual time=0.003..0.193 rows=3503 loops=1) -> Hash (cost=6.47..6.47 rows=347 width=27) (actual time=0.054..0.055 rows=347 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 29kB -> Seq Scan on "Album" a (cost=0.00..6.47 rows=347 width=27) (actual time=0.003..0.025 rows=347 loops=1) SubPlan 1 -> Aggregate (cost=16.23..16.24 rows=1 width=8) (actual time=0.022..0.022 rows=1 loops=3503) -> Nested Loop (cost=0.28..16.22 rows=3 width=0) (actual time=0.011..0.022 rows=7 loops=3503) -> Seq Scan on "Album" (cost=0.00..7.34 rows=1 width=4) (actual time=0.008..0.018 rows=1 loops=3503) Filter: (("Title")::text = (a."Title")::text) Rows Removed by Filter: 346 -> Index Scan using "IFK_TrackAlbumId" on "Track" (cost=0.28..8.85 rows=3 width=4) (actual time=0.001..0.003 rows=7 loops=3503) Index Cond: ("AlbumId" = "Album"."AlbumId") Filter: ("Milliseconds" < t."Milliseconds") Rows Removed by Filter: 8 Planning Time: 0.206 ms Execution Time: 80.561 ms Summarized: Lateral: (cost=16.37..5701.03 rows=694 rows=1168) (actual time=0.043..7.347 ) C Subq: (cost=10.81..148.79 rows=1168 width=43) (actual time=0.109..80.502) with the actual amount of rows for this queries being 612, so the amount of rows for the C Subq is not well estimated. Nonetheless in this case, the most expensive query here, is the fastest one. (PS: Analyze was run on the tables prior to the queries) -- mvg, Wim Bertels -- https://coronalert.be -- "Not Hercules could have knock'd out his brains, for he had none." -- Shakespeare --=-jMZZM47WsG/85TSARXdV Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
Hello,
=
Using the chinook database
locally,=
so there should be little side-effects (network, host, cache..)<= /div>
for the following two equivalent queries,
the cost and = execution times are curious.

(tip if you have prob= lems on linux psql for the chinook database
#set client_enco= ding to 'windows-1251';
)

Can anyone con= firm or correct this?

The equivalent queries are

SELECT r1."Title",hs."Name",hs.= "Milliseconds"
FROM "Album" r1 LEFT JOIN LATE= RAL
 (SELECT *
 FROM "Track" b2
natural inner join "Album"
 WHERE r1."= AlbumId" =3D b2."AlbumId"
 ORDER BY "Mil= liseconds" desc
 FETCH FIRST 2 ROW ONLY) hs
O= N true;

vs

SELECT "T= itle", "Name", "Milliseconds"
FROM "= ;Album" A NATURAL INNER JOIN "Track" T
WHERE 1 >= ;=3D (SELECT COUNT(*)
       &= nbsp;           FROM= "Album" NATURAL INNER JOIN "Track"
 &nb= sp;            =      WHERE "Album"."Title" =3D= A."Title"
       &n= bsp;           AND &= quot;Track"."Milliseconds" < T."Milliseconds");=


Running explain (analyz= e) a few times gives the following curious result:

With the Lateral join query:
      = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;    QUERY PLAN      &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;    
--------------------------------------= ---------------------------------------------------------------------------= -------------------------------------------
 Nested Loop Lef= t Join  (cost=3D16.37..5701.03 rows=3D694 width=3D43) (actual tim= e=3D0.043..7.347 rows=3D612 loops=3D1)
   ->&nb= sp; Seq Scan on "Album" r1  (cost=3D0.00..6.47 row= s=3D347 width=3D27) (actual time=3D0.006..0.022 rows=3D347 loops=3D1)
=
   ->  Limit  (cost=3D16.37..16.= 37 rows=3D2 width=3D856) (actual time=3D0.021..0.021 rows=3D2 loops=3D347)<= /div>
         -> =  Sort  (cost=3D16.37..16.39 rows=3D10 width=3D856) (actual t= ime=3D0.021..0.021 rows=3D2 loops=3D347)
    =            Sort Key:= b2."Milliseconds" DESC
     &= nbsp;         Sort Method: qui= cksort  Memory: 25kB
     &nbs= p;         ->  Ne= sted Loop  (cost=3D0.28..16.27 rows=3D10 width=3D856) (actual tim= e=3D0.009..0.019 rows=3D10 loops=3D347)
    &= nbsp;           &nbs= p;    ->  Seq Scan on "Album"&nb= sp; (cost=3D0.00..7.34 rows=3D1 width=3D4) (actual time=3D0.008..0.016= rows=3D1 loops=3D347)
       =             &nb= sp;       Filter: ("AlbumId" = =3D r1."AlbumId")
      &= nbsp;           &nbs= p;        Rows Removed by Filter: 3= 46
          &n= bsp;          -> =  Index Scan using "IFK_TrackAlbumId" on "Track" b2=   (cost=3D0.28..8.83 rows=3D10 width=3D24) (actual time=3D0.001..= 0.002 rows=3D10 loops=3D347)
      =             &nb= sp;        Index Cond: ("Album= Id" =3D r1."AlbumId")
 Planning Time: 0.094 m= s
 Execution Time: 7.388 ms

<= div>
With the correlated subquery (where):
 &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;    QUERY PLAN      &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            <= /div>
-----------------------------------------------------------------= ---------------------------------------------------------------------------= -------
 Hash Join  (cost=3D10.81..148.79 rows=3D1= 168 width=3D43) (actual time=3D0.109..80.502 rows=3D612 loops=3D1)
   Hash Cond: (t."AlbumId" =3D a."AlbumId&q= uot;)
   Join Filter: (1 >=3D (SubPlan 1))
   Rows Removed by Join Filter: 2891
 &= nbsp; ->  Seq Scan on "Track" t  (cos= t=3D0.00..80.03 rows=3D3503 width=3D24) (actual time=3D0.003..0.193 rows=3D= 3503 loops=3D1)
   ->  Hash &nbs= p;(cost=3D6.47..6.47 rows=3D347 width=3D27) (actual time=3D0.054..0.055 row= s=3D347 loops=3D1)
       &nbs= p; Buckets: 1024  Batches: 1  Memory Usage: 29kB
         -> &= nbsp;Seq Scan on "Album" a  (cost=3D0.00..6.47 rows=3D3= 47 width=3D27) (actual time=3D0.003..0.025 rows=3D347 loops=3D1)
=    SubPlan 1
     ->&n= bsp; Aggregate  (cost=3D16.23..16.24 rows=3D1 width=3D8) (ac= tual time=3D0.022..0.022 rows=3D1 loops=3D3503)
   = ;        ->  Nested Lo= op  (cost=3D0.28..16.22 rows=3D3 width=3D0) (actual time=3D0.011.= .0.022 rows=3D7 loops=3D3503)
      = ;           ->&nb= sp; Seq Scan on "Album"  (cost=3D0.00..7.34 rows= =3D1 width=3D4) (actual time=3D0.008..0.018 rows=3D1 loops=3D3503)
            &= nbsp;          Filter: ((= "Title")::text =3D (a."Title")::text)
 &= nbsp;           &nbs= p;         Rows Removed by Fil= ter: 346
         &n= bsp;       ->  Index Scan u= sing "IFK_TrackAlbumId" on "Track"  (cost=3D0= .28..8.85 rows=3D3 width=3D4) (actual time=3D0.001..0.003 rows=3D7 loops=3D= 3503)
          = ;            &n= bsp;Index Cond: ("AlbumId" =3D "Album"."AlbumId&qu= ot;)
          =             &nb= sp;Filter: ("Milliseconds" < t."Milliseconds")
=
           &nbs= p;           Rows Re= moved by Filter: 8
 Planning Time: 0.206 ms
 = Execution Time: 80.561 ms

Summarized:

Lateral:  (cost=3D16.37..5701.03 rows=3D694&nb= sp;rows=3D1168) (actual time=3D0.043..7.347 )
C Subq: (cost=3D10.= 81..148.79 rows=3D1168 width=3D43) (actual time=3D0.109..80.502)
= with the actual amount of rows for this queries being 612,
so the= amount of rows for the C Subq is not well estimated.

<= div>Nonetheless in this case, the most expensive query here, is the fastest= one.

(PS: Analyze was run on the tables prior to = the queries)

-- 
mvg, Wim Bertels -- https://coronalert.be -- "Not Hercules could have knock'd out his brains, for he had none."= ; -- Shakespeare
--=-jMZZM47WsG/85TSARXdV--