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 1pKN9r-0002Jn-8k for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jan 2023 17:32:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pKN9p-0006aX-Sc for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jan 2023 17:32:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pKN9p-0006XH-J0 for pgsql-hackers@lists.postgresql.org; Tue, 24 Jan 2023 17:32:29 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pKN9j-0008RP-2H for pgsql-hackers@lists.postgresql.org; Tue, 24 Jan 2023 17:32:28 +0000 Received: by mail-pf1-x42d.google.com with SMTP id a184so11689792pfa.9 for ; Tue, 24 Jan 2023 09:32:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=ssY/O+FXHsS9kNdEmbqcPGpeKM501f6IwcZP0NFoUiM=; b=Q+K1B6JCCjN7NQaHbxOURyoEEw2AqS35XA28aqTjC6nCijs68n7Jf2d0DIVSqH+QGY DgPTqXt87wpb996A3gnujHMe4E6A42UlHsnbwHusAM/7Qu/sjPtu+J7RGEi56TWXL/6U hq86qdfv5MMJkZNuRhMZ0Hp0vpmv0/u/Hzj68p0x/18sTp9PT4gKP58lnJDxiOyDtZIS hLjJYEBbnfGCtPlj+qBKXf0kpFfJVdZuTlC8ZvjXL+SeVobvC4TGZ0fFKiEO1wkTGzHp kI6gIhZjtFRw5KFKJe/EiLFG+HtIVmpDB/8ttihTaM7fr9ERmrW7ZnKF41ag0rwISX0W z6Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ssY/O+FXHsS9kNdEmbqcPGpeKM501f6IwcZP0NFoUiM=; b=5WheGLNqfEk6bbAWGiE6xxV2ni609l2qFSXZTO5RkNWqsa1YLFM8Wedk+urwbttQ5c gFdXmKWfgAXz6OFZS4Wd2Wbpk23YOdIpxHM+80n98uRKob+N/LeCj57vrWnCDtj5c+lo 63aJbOyWqC74qfN2IJz4ZHvz0dQaKrlDRCenQIHMryHdI/70Hgj2N1VElCy9NwfRu7ng CehrhNc0ajumIpjrIZCjK9kfIZVGOgRs+TBtin8d8O2FIxInf/kqA54rt9jvv8N6uhuk zvXBijgi0nkCRQuWvDasNlliqb9m2OFQO7NImAEMPxfFjPnacSKvd+nmWCKNhAYwscCO 6jCw== X-Gm-Message-State: AFqh2krQl9bYE+LV2mWwENW9jdBmfIc/hvNwHoJR0mQLeJF7IZLWTiZY E+4HLa99M+kkvdUdfRQs0bQ= X-Google-Smtp-Source: AMrXdXuCTXTX5R5hJj6nLFDA8T2IWskuYcxyDjqPAY6wTo+8Evz3ASDVqyKT9SyqKAeNJBYLVARYxA== X-Received: by 2002:aa7:9e0c:0:b0:58d:ae6d:14d5 with SMTP id y12-20020aa79e0c000000b0058dae6d14d5mr30230004pfq.27.1674581541874; Tue, 24 Jan 2023 09:32:21 -0800 (PST) Received: from [10.0.2.15] ([115.99.107.105]) by smtp.gmail.com with ESMTPSA id l22-20020a62be16000000b00576259507c0sm1863067pff.100.2023.01.24.09.32.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Jan 2023 09:32:21 -0800 (PST) Message-ID: <5314d2fc-76b6-c4ea-c083-1ef11411e5be@gmail.com> Date: Tue, 24 Jan 2023 23:02:18 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: Todo: Teach planner to evaluate multiple windows in the optimal order From: Ankit Kumar Pandey To: David Rowley Cc: pghackers , Vik Fearing References: <83d80853-a45c-d85c-68eb-59acfe7fb5fb@gmail.com> <01248493-182b-0f92-f2f2-ff28dc4b2e83@gmail.com> <2040c902-32b1-46c8-0b26-d3f43a16b9bb@gmail.com> <12f6ef19-e06e-8ea9-ad98-3fd92afb7f0b@gmail.com> <8d0b24ce-f8ba-cd63-82ae-be853b4067e8@gmail.com> <4ef7f947-526b-c4ec-f7a0-8b4586e693e4@gmail.com> <8599211e-1ea9-8827-4b9b-adeb865656bd@gmail.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > I think more benchmarking is required > so we can figure out if this is a corner case or a common case I did some more benchmarks: #1. AIM: Pushdown column whose size is very high create table test(a int, b int, c text); insert into test select a,b,c from generate_series(1,1000)a, generate_series(1,1000)b, repeat(md5(random()::text), 999)c; explain (analyze, costs off) select count(*) over (order by a), row_number() over (order by a, b) from test order by a,b,c; QUERY PLAN ---------------------------------------------------------------------------------------------------------- Incremental Sort (actual time=1161.605..6577.141 rows=1000000 loops=1) Sort Key: a, b, c Presorted Key: a, b Full-sort Groups: 31250 Sort Method: quicksort Average Memory: 39kB Peak Memory: 39kB -> WindowAgg (actual time=1158.896..5819.460 rows=1000000 loops=1) -> WindowAgg (actual time=1154.614..3391.537 rows=1000000 loops=1) -> Gather Merge (actual time=1154.602..2404.125 rows=1000000 loops=1) Workers Planned: 2 Workers Launched: 2 -> Sort (actual time=1118.326..1295.743 rows=333333 loops=3) Sort Key: a, b Sort Method: external merge Disk: 145648kB Worker 0: Sort Method: external merge Disk: 140608kB Worker 1: Sort Method: external merge Disk: 132792kB -> Parallel Seq Scan on test (actual time=0.018..169.319 rows=333333 loops=3) Planning Time: 0.091 ms Execution Time: 6816.616 ms (17 rows) Planner choose faster path correctly (which was not path which had pushed down column). #2. AIM: Check strict vs incremental sorts wrt to large size data Patch version is faster as for external merge sort, disk IO is main bottleneck and if we sort an extra column, it doesn't have major impact. This is when work mem is very small. For larger work_mem, difference between patched version and master is minimal and they both provide somewhat comparable performance. Tried permutation of few cases which we have already covered but I did not see anything alarming in those. > I'm just unsure if we should write this off as the expected behaviour > of Sort and continue with the patch or delay the whole thing until we > make some improvements to sort. I am not seeing other cases where patch version is consistently slower. Thanks, Ankit