Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hsFpT-0003Hp-H7 for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jul 2019 00:17:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hsFpS-0005l2-3Y for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jul 2019 00:17:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hsFpR-0005kv-Ng for pgsql-hackers@lists.postgresql.org; Tue, 30 Jul 2019 00:17:21 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hsFpO-0006BS-Bf for pgsql-hackers@lists.postgresql.org; Tue, 30 Jul 2019 00:17:21 +0000 Received: by mail-wm1-x341.google.com with SMTP id a15so55399601wmj.5 for ; Mon, 29 Jul 2019 17:17:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=c/76NQQfMlIHXYYe/dGT6jez3gRLm/WCAi2E6LWdAtY=; b=tePIB1ZA60btf4ZqB8VyWNhXt8dUbeGn3I4Fc2asUKe6msOWKxsP9Hn9KABB2BtWrQ PDI2ro3LzlCPKQewRNNag8vpV3YUXHaLvr+KRVX4MA6xYLKLeHncQUu4CvRROM87m0Sc k88ensjnG3WQvYx9BOMQABlWeJbxRIBhyB/t/zaJpg7bmrYLPWIznBUwFTPF8OF+BowN +l8yzvcx0a4tMwXKq3QRsEtDYmc6dEl3+9j9tip9EtaVAbwOiRpwjus1ytqFt2UnhCS9 dhzRgDHLekv1rqsaoL12ryvLXcfl+w9CgK8/4ULBRgqYs5gzRHEVkGDLs8oX2vwKN9lo Jt3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=c/76NQQfMlIHXYYe/dGT6jez3gRLm/WCAi2E6LWdAtY=; b=cXuBcciFUuAEnY2xFCGEabcDFQ2qgUzcNnSrRHqnzAgd/TLayIDOzu+GuJTVee7UOq yMmbG26uGaytG721QH6ibtUweIYsPDw/HH7qSy2FSyoNSu2+DyFH0WYBMnf8EOxxoST9 bKlbk5x7AX5c0mhJOc7jHlsXAlRVazWT/OGsG5oKCD1pq9JQJCzEtmMIFY+LrE+Bkaq8 ylYupJB4lOS+cxCQsOLVJ2QQB32AwXEMHfXvs7Qya6bicTaWuHiHcVlog1aH20z0oFqh YWFyVKRBklx2Z6Y/HGt7bHvuKYYde+J5v7sGvp6lWBWHgJFiuR+LN9IW+7EcutlHI8mJ Ve7g== X-Gm-Message-State: APjAAAWxGnq+uUk9iT+cviC1CA+/13rXdmT9M6iJLn9i/mb/fqb6f/s2 5bdGlFZbX//qgOgld4rg+CbcJg== X-Google-Smtp-Source: APXvYqzcX5nuD2StXHB6ynl2PzSiHyghqm/w0Nl6755Tk4EM7eZV+EB7x2lyDzvPZCIjO+mNXO1dqA== X-Received: by 2002:a1c:1a4c:: with SMTP id a73mr40822069wma.109.1564445834466; Mon, 29 Jul 2019 17:17:14 -0700 (PDT) Received: from localhost (ip-86-49-253-160.net.upcbroadband.cz. [86.49.253.160]) by smtp.gmail.com with ESMTPSA id j16sm5000388wrp.62.2019.07.29.17.17.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 17:17:12 -0700 (PDT) Date: Tue, 30 Jul 2019 02:17:11 +0200 From: Tomas Vondra To: James Coleman Cc: Peter Geoghegan , Simon Riggs , Rafia Sabih , Shaun Thomas , Dmitry Dolgov <9erthalion6@gmail.com>, Alexander Korotkov , Tom Lane , PostgreSQL Developers Subject: Re: [PATCH] Incremental sort (was: PoC: Partial sort) Message-ID: <20190730001711.hprrcx3ntk57wuqv@development> References: <20190709013703.3mbdhsv2gyxtjc42@development> <20190720132244.3vgg2uynfpxh3me5@development> <20190720152512.jpdi2g3notbjcxsd@development> <20190720165951.m6adwbqi26bsfbjb@development> <20190721113422.hjubqs45xxpnldn7@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20190721113422.hjubqs45xxpnldn7@development> User-Agent: NeoMutt/20180716-1444-295967 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, Jul 21, 2019 at 01:34:22PM +0200, Tomas Vondra wrote: > > ... > >I wonder if we're approaching this wrong. Maybe we should not reverse >engineer queries for the various places, but just start with a set of >queries that we want to optimize, and then identify which places in the >planner need to be modified. > I've decided to do a couple of experiments, trying to make my mind about which modified places matter to diffrent queries. But instead of trying to reverse engineer the queries, I've taken a different approach - I've compiled a list of queries that I think are sensible and relevant, and then planned them with incremental sort enabled in different places. I don't have any clear conclusions at this point - it does show some of the places don't change plan for any of the queries, although there may be some additional query where it'd make a difference. But I'm posting this mostly because it might be useful. I've initially planned to move changes that add incremental sort paths to separate patches, and then apply/skip different subsets of those patches. But then I realized there's a better way to do this - I've added a bunch of GUCs, one for each such place. This allows doing this testing without having to rebuild repeatedly. I'm not going to post the patch(es) with extra GUCs here, because it'd just confuse the patch tester, but it's available here: https://github.com/tvondra/postgres/tree/incremental-sort-20190730 There are 10 GUCs, one for each place in planner where incremental sort paths are constructed. By default all those are set to 'false' so no incremental sort paths are built. If you do SET devel_create_ordered_paths = on; it'll start creating the paths in non-parallel in create_ordered_paths. Then you may enable devel_create_ordered_paths_parallel to also consider parallel paths, etc. The list of queries (synthetic, but hopefully sufficiently realistic) and a couple of scripts to collect the plans is in this repository: https://github.com/tvondra/incremental-sort-tests-2 There's also a spreadsheet with a summary of results, with a visual representation of which GUCs affect which queries. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services