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.92) (envelope-from ) id 1jCXRG-0007IG-CC for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2020 23:40:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jCXRE-0001Wv-CM for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2020 23:40:28 +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 1jCXRE-0001Wi-3G for pgsql-hackers@lists.postgresql.org; Thu, 12 Mar 2020 23:40:28 +0000 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jCXR7-0003Ih-7z for pgsql-hackers@lists.postgresql.org; Thu, 12 Mar 2020 23:40:27 +0000 Received: by mail-qk1-x743.google.com with SMTP id z25so4599706qkj.4 for ; Thu, 12 Mar 2020 16:40:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-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=eixxq6OFvj7iwD8yPcmKR02zKeF0UpDbqm3NavUGYwA=; b=0kF1DAy+rFVBxc2hFfsuZNaBhECMiJoVWeDCanTBOxhVINJ7Z+D8jR9+ycxVVdWZRT 7m0lNTE/1YjemlvtHXoDqZyxbNRTvN4fXLfk9eWOwhjZ2Umol1nNIg4hIhHQBqabpQ3w ezv1HjCa2oKTSudEXGOlxFZvWUbiSjAxEMkljpPL2//DIJkkTMKyJeD5UlR0r2/1it2o YIVtVoGoPzENccTMe3YoHtrmtSp0R9ut7hhpMfaFTIMpaIBd8QO7MQ8fMcyDL7FbzYZ9 Nx/0BI3ORkBVgaDYWSIxNAG22OlB5OjNBSA8GkOqxSYDvPLCh8UcA3vTBIBdC5eE4Z6a rURQ== 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=eixxq6OFvj7iwD8yPcmKR02zKeF0UpDbqm3NavUGYwA=; b=qYqhSYu+jFQh8xKSP0FPIzZW5i8oGeFFwROLsadiHk5R+ZxraWGwH1teTya+T7ekqW pxH2dLxTeY9DYHuOKuTKS367LiNal1yOFxkcNLcfTcGrItV3Tzf3Z3BxzZ2cStx9bpA9 FAIr6iMnQUbTOeDKTghlCVwezbIP29+SOAGeb6Ozbs58H0R43lUOEsGCwxvbvJmNZrVH /GO+6ebyqHr6SWzrq1WeO1xqL6ltMOqar2hxOpYP1eoShlf3Z7YG6uE78kPvdyj3FgjN 0C/u1VlLwOVam5XZpsEtvWMzSOQ4KQA7by4IYsg0mlOwN/le9DJ2IerC9jjETZew2fN/ JMYQ== X-Gm-Message-State: ANhLgQ0HSnXjJYKGv3vp64I6KIj0gGSL1EQ+9PxfxyNljnMqwVdI8uv/ EDlFDn1Fmh3SslhKJcUDTwksdw== X-Google-Smtp-Source: ADFU+vvDFM5KR2m53rmdde9s2Nvnqz2Khhi4gHLiVZm7By90feNfE8pt+5J85g0nkuMLWJegNCkEMA== X-Received: by 2002:a37:85c2:: with SMTP id h185mr10292913qkd.446.1584056419385; Thu, 12 Mar 2020 16:40:19 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id x22sm7060193qki.54.2020.03.12.16.40.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Mar 2020 16:40:18 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 203EA800719; Thu, 12 Mar 2020 18:40:15 -0500 (CDT) Date: Thu, 12 Mar 2020 18:40:15 -0500 From: Justin Pryzby To: Tomas Vondra Cc: James Coleman , Michael Paquier , Rafia Sabih , Peter Geoghegan , Simon Riggs , Shaun Thomas , Dmitry Dolgov <9erthalion6@gmail.com>, Alexander Korotkov , Tom Lane , pgsql-hackers@lists.postgresql.org, Alvaro Herrera Subject: Re: [PATCH] Incremental sort (was: PoC: Partial sort) Message-ID: <20200312234014.GI29065@telsasoft.com> References: <20190909215538.42hrv6j4z5ztcft4@development> <20190928230049.k4l2mayun7jomhxy@development> <20191129060146.GH2505@paquier.xyz> <20191201004716.cenkc33em2lnrrdl@development> <20200121142529.wpickvfefp7lok4p@development> <20200311024355.5h2v56jpgzvd7yox@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200311024355.5h2v56jpgzvd7yox@development> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thanks for working on this. I have some minor comments. In 0005: + /* Restore the input path (we might have addes Sort on top). */ => added? There's at least two more of the same typo. + /* also ignore already sorted paths */ => You say that in a couple places, but I don't think "also" makes sense since there's nothing preceding it ? In 0004: + * end up resorting the entire data set. So, unless we can push => re-sorting + * Unlike generate_gather_paths, this does not look just as pathkeys of the => look just AT ? + /* now we know is_sorted == false */ => I would just spell that "Assert", as I think you already do elsewhere. + /* continue */ => Please consider saying "fall through", since "continue" means exactly the opposite. +generate_useful_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows) ... + /* finally, consider incremental sort */ ... + /* Also consider incremental sort. */ => I think it's more confusing than useful with two comments - one is adequate. In 0002: + * If it's EXPLAIN ANALYZE, show tuplesort stats for a incremental sort node ... + * make_incrementalsort --- basic routine to build a IncrementalSort plan node => AN incremental + * Initial size of memtuples array. We're trying to select this size so that + * array don't exceed ALLOCSET_SEPARATE_THRESHOLD and overhead of allocation + * be possible less. However, we don't cosider array sizes less than 1024 Four typos (?) that array DOESN'T and THE overhead CONSIDER I'm not sure, but "be possible less" should maybe say "possibly be less" ? + bool maxSpaceOnDisk; /* true when maxSpace is value for on-disk I suggest to call it IsMaxSpaceDisk + MemoryContext maincontext; /* memory context for tuple sort metadata + that persist across multiple batches */ persists + * a new sort. It allows evade recreation of tuple sort (and save resources) + * when sorting multiple small batches. allows to avoid? Or allows avoiding? + * When performing sorting by multiple keys input dataset could be already + * presorted by some prefix of these keys. We call them "presorted keys". "already presorted" sounds redundant + int64 fullsort_group_count; /* number of groups with equal presorted keys */ + int64 prefixsort_group_count; /* number of groups with equal presorted keys */ I guess these should have different comments -- Justin