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 1pLgSj-0000Ak-Tx for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Jan 2023 08:21:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pLgSh-0006z4-6l for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Jan 2023 08:21:23 +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 1pLgSg-0006yu-RK for pgsql-hackers@lists.postgresql.org; Sat, 28 Jan 2023 08:21:22 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pLgSZ-00010s-Pb for pgsql-hackers@lists.postgresql.org; Sat, 28 Jan 2023 08:21:22 +0000 Received: by mail-pl1-x636.google.com with SMTP id p24so7100012plw.11 for ; Sat, 28 Jan 2023 00:21:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=TOzRxWAMWS+QjyGe3lV0vD7NRZ8qVIlHzBITzA9WE3Y=; b=BnGeX32ouPcDcqNPLVEidkXSuYdPG72UFZJizPNwBKLPm/rsUIafIQ0cVeQVs5Hksn 8dAM5oJ9OE1mpcYFMeDQUCTlttlFL0q9WsaTvQr50osSaWjCnWJ8KhYMIgCmvUdEfshF d8DDrPaqQoF8qWiC8UCxHFs6PehVomlUaLKSB2KlhW4NjlowQugtfdyLk4/zV2j5b3Vp qe4rW7t74h5qVrfWvbIT0C/30hC3lt5njOt7tbCujF5P/mnIEjeWufzqDR8nuJyxNQSS 9lQ7ahzv2sp98PvbfIjhxOXEe0TI89eiUy8kmIFwcsmTdcf2r/pBPQrzZ9i0NXB5REUi N31w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TOzRxWAMWS+QjyGe3lV0vD7NRZ8qVIlHzBITzA9WE3Y=; b=GQBzRLvXoLkxVvwG5PFMwWAXhzn52+deKPrLPTerDulA1t776wTCXZa16MDhxS8emx WC4uNkdb+GTyv+A59Jbx/6Bmk5AxsJvqoDkVHA8pssUksmNFNB+FBa2K2kPNL7zIgTIQ +UAuHCitfAjWlBpKg0ewd99EXvX7LglRZtL3O0E938ILIO6FW/whPj84HZ/ZHPnD1Wt8 PTjR3er8LpqVs6rTMWL+llxnXCWQhfxHobSjFAoE5CBa50ODkI1PIySaSgjoIScPiovx 7vx9kDMg8jk0LeGi6xcAFn1HyhElM2a3qP9D48kRTFyRmW0blrJFAaMC+s6AAkV5K6V1 JdkQ== X-Gm-Message-State: AFqh2kqpVjMceuJHnOzeDALr2RTCwVNW992pS0dPa4O9/NZKXyWHnGQj tEGmFd/m/h5CRri5JbFrXYI= X-Google-Smtp-Source: AMrXdXtCd3HPlb59B0CjbdubIw6tGoamJCYhlKZeFeQUqMd/9nbboHBDHakPJ6WczbFuhaMXq5JSCw== X-Received: by 2002:a05:6a20:9399:b0:9d:efbf:7864 with SMTP id x25-20020a056a20939900b0009defbf7864mr51425960pzh.25.1674894073780; Sat, 28 Jan 2023 00:21:13 -0800 (PST) Received: from [10.0.2.15] ([116.75.105.183]) by smtp.gmail.com with ESMTPSA id x18-20020aa79412000000b005821db4fd84sm3782424pfo.131.2023.01.28.00.21.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 28 Jan 2023 00:21:12 -0800 (PST) Message-ID: <52a3def2-4d2b-fb76-e334-5079ac67d7c7@gmail.com> Date: Sat, 28 Jan 2023 13:51:09 +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 To: David Rowley Cc: pghackers , Vik Fearing References: <83d80853-a45c-d85c-68eb-59acfe7fb5fb@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> <5314d2fc-76b6-c4ea-c083-1ef11411e5be@gmail.com> Content-Language: en-US From: Ankit Kumar Pandey 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 > On 26/01/23 07:40, David Rowley wrote: > You can see from the results that the patched version is not looking > particularly great. I did a 1 million row test and a 10 million row > test. work_mem was 4GB for each, so the sorts never went to disk. Yes, its lackluster gains are very limited (pretty much when data gets pushed to disk). > I'm unsure if 69749243 might be partially to blame here as it favours > single-key sorts. If you look at qsort_tuple_signed_compare(), you'll > see that the tiebreak function will be called only when it's needed > and there are > 1 sort keys. The comparetup function will re-compare > the first key all over again. If I get some more time I'll run the > tests again with the sort specialisation code disabled to see if the > situation is the same or not. > Another way to test that would be to have a table with 3 columns and > always sort by at least 2. I will need to go through this. > I've attached the benchmark script that I used and also a copy of the > patch with a GUC added solely to allow easier benchmarking of patched > vs unpatched. This is much relief, will be easier to repro and create more cases. Thanks. > I think we need to park this patch until we can figure out what can be > done to stop these regressions. Makes sense. > We might want to look at 1) Expanding > on what 69749243 did and considering if we want sort specialisations > that are specifically for 1 column and another set for multi-columns. > The multi-column ones don't need to re-compare key[0] again. 2) > Sorting in smaller batches that better fit into CPU cache. Both of > these ideas would require a large amount of testing and discussion. > For #1 we're considering other specialisations, for example NOT NULL, > and we don't want to explode the number of specialisations we have to > compile into the binary. Yes, 1 & 2 needs to be addressed before going ahead with this patch. Do we any have ongoing thread with #1 and #2? Also, we have seen an issue with cost ( 1 sort vs 2 sorts, both having same cost) https://www.postgresql.org/message-id/CAApHDvo2y9S2AO-BPYo7gMPYD0XE2Lo-KFLnqX80fcftqBCcyw@mail.gmail.com This needs to be investigated too (although might not be related but need to check at least) I will do some study around things mentioned here and will setup new threads (if they don't exists) based on discussions we had here . Thanks, Ankit