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 1jIOPQ-00073t-Py for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Mar 2020 03:14:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jIOPO-00080s-Ag for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Mar 2020 03:14:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jIOPN-00080l-Qj for pgsql-hackers@lists.postgresql.org; Sun, 29 Mar 2020 03:14:46 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jIOPK-0005rd-Bq for pgsql-hackers@lists.postgresql.org; Sun, 29 Mar 2020 03:14:44 +0000 Received: by mail-wm1-x344.google.com with SMTP id z18so16030241wmk.2 for ; Sat, 28 Mar 2020 20:14:42 -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; bh=CT7DQzuEPR7gOSpBcRUFj9eigYDg4lRmoufrBo5WOgQ=; b=x+EmqZTaFTAdNqNZoKzsomeTSBPG8MDKMDPEmmg5KO5ruAGfqc7A/UNjMNzAEgU3uk DxOHMtCleb9I+7RIW03b6c5aCC2mzrrGoj7RuLlZr0u+psFMO7DB7Pwuo44eHGaqIE9r xWxTAHAil9UW9XQN+zwsbsuoUaQuwpaWsSsaDxTEC/JRypQo6MTMVqWA+Gr7IT3/Kdpe Vf6aJU6Q6q8tetd7fuNiWMt1nnKW7MTU7rf0nq0Go9qN/CvPVYScr3AguMCcT2K+5Q46 JHs6KQTKwdtXmO9OISZabGtT3SZw+XtDvS5KMnR4/E/sesUNHuUY6i8TT/yh8I3Vvt23 QMuw== 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; bh=CT7DQzuEPR7gOSpBcRUFj9eigYDg4lRmoufrBo5WOgQ=; b=hjU5ViDIjlBZG2knpxS/Z1eMF/b3W8buwKiDilA5cNcKYeX13op8yoYRs3u0Fy8FBa zTXp2QSNlR2Cq2cbSW1er8ze1v8ku3rdTgTRKXC8uS20yFDGXSyhapwUfcsabK3b3+br bSsGqzTsugWOUFouBBi/uiejQ5NAPTRnX6Yen+vWLroSpkG34XyVX7P9rNVByuO5QO64 NwIhiJUpn0/9komXLNrOFd1C5AtLJ6QTUyvOMknMYGZ3CLmf66+M8xdMETYBHDUVI4Yj B01aYM4kySfGzxxELYiwaUWvKyWogviF47hVSVgXzZT8idsdQiJAJ8Q/owKpQ1ClGOG7 mBJQ== X-Gm-Message-State: ANhLgQ1iKkBir2zwcCVbHPJqtCkT4Yj1BZNVzfy3B6s/aylEDXA1mwJs rSYjoZhUASDLUtE8w1Qgd6Zw+g== X-Google-Smtp-Source: ADFU+vt8EacO8Zu07uqv2QdER4dU07VtnwaFXOoXTQZzKEpoqIPxMgSrczF4ucDKfTmMSwpYDIVh4A== X-Received: by 2002:a7b:caaa:: with SMTP id r10mr6321111wml.119.1585451680708; Sat, 28 Mar 2020 20:14:40 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id p22sm14275425wmg.37.2020.03.28.20.14.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 20:14:39 -0700 (PDT) Date: Sun, 29 Mar 2020 05:14:37 +0200 From: Tomas Vondra To: James Coleman Cc: Alvaro Herrera , Michael Paquier , Rafia Sabih , Peter Geoghegan , Simon Riggs , Shaun Thomas , Dmitry Dolgov <9erthalion6@gmail.com>, Alexander Korotkov , Tom Lane , PostgreSQL Developers , Andreas Karlsson Subject: Re: [PATCH] Incremental sort (was: PoC: Partial sort) Message-ID: <20200329031437.yvhogo25wdijwpqd@development> References: <20200328011913.btjuwwkhieav3aod@development> <20200328025830.6v6ogkseohakc32q@development> <20200328213050.byyeuozylnxv2bhf@development> <20200328225922.ljnw54bfg44vi6ib@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Mar 28, 2020 at 10:47:49PM -0400, James Coleman wrote: >On Sat, Mar 28, 2020 at 6:59 PM Tomas Vondra > wrote: >> >> Hi, >> >> Attached is my take on simplification of the useful pathkeyes thing. It >> keeps the function, but it truncates query_pathkeys to only members with >> EC members in the relation. I think that's essentially the optimization >> you've proposed. > >Thanks. I've included that in the patch series in this email (as a >separate patch) with a few additional comments. > Thanks. >I've also noticed that the enabled_incrementalsort check in >generate_useful_gather_paths seemed broken, because it returned us out >of the function before creating either a plain gather merge (if >already sorted) or an explicit sort path. I've included a patch that >moves it to the if block that actually builds the incremental sort >path. > Hmmm, that's probably right. The reason why the GUC check was right after generate_gather_paths is that the intent to disable all the useful-pathkeys business, essentially reducing it back to plain generate_gather_paths. But I think you're right that's wrong, because it might lead to strange behavior when the GUC switches between plans without any incremental sort nodes - setting it to 'true' might end up picking GM on top of plain Sort, for example. >> >> ... >> >> 1) Missing worker identification (Worker #). > >Fixed. > >> 2) Missing method for workers (we have it for the leader, though). > >Fixed. Since we can't have pointers in the parallel shared memory >space, we can't store the sort methods used in a list. To accomplish >the same goal, I've assigned the TuplesortMethod enum entries uique >bit positions, and store the methods used in a bitmask. > OK, makes sense. >> 3) I'm not sure why the lable is "Methods" instead of "Sort Method", and >> why it's in parenthesis. > >I've removed the parentheses. It's labeled "Methods" since there can >be more than one (different batches could use different methods). I've >updated this to properly use singular/plural depending on the number >of methods used. > I'm a bit confused. How do I know which batch used which method? Is it actually worth printing in explain analyze? Maybe only print it in the verbose mode? >> 4) Not sure having two lines for each worker is a great idea. > >I've left these in for now because the lines are already very long >(much, much longer than the worker lines in a standard sort node). >This is largely because we're trying to summarize many sort batches, >while standard sort nodes only have to give the exact stats from a >single batch. > >See the example output later in the email. > OK >> 5) I'd probably prefer having multiple labels for avg/max memory values, >> instead of (avg) and (max) notes. Also, I think we use "peak" in this >> context instead of "max". > >Updated. > OK >Here's the current output: > > Limit (cost=1887419.20..1889547.68 rows=10000 width=8) (actual >time=13218.403..13222.519 rows=10000 loo >ps=1) > -> Gather Merge (cost=1887419.20..19624748.03 rows=83333360 >width=8) (actual time=13218.401..13229.7 >50 rows=10000 loops=1) > Workers Planned: 2 > Workers Launched: 2 > -> Incremental Sort (cost=1886419.17..10005010.55 >rows=41666680 width=8) (actual time=13208.00 >4..13208.586 rows=4425 loops=3) > Sort Key: a, b > Presorted Key: a > Full-sort Groups: 1 Sort Method: quicksort Memory: >avg=28kB peak=28kB > Presorted Groups: 1 Sort Method: top-N heapsort Memory: >avg=1681kB peak=1681kB > Worker 0: Full-sort Groups: 1 Sort Method: quicksort >Memory: avg=28kB peak=28kB > Presorted Groups: 1 Sort Method: top-N heapsort >Memory: avg=1680kB peak=1680kB > Worker 1: Full-sort Groups: 1 Sort Method: quicksort >Memory: avg=28kB peak=28kB > Presorted Groups: 1 Sort Method: top-N heapsort >Memory: avg=1682kB peak=1682kB > -> Parallel Index Scan using index_s_a on s >(cost=0.57..4967182.06 rows=41666680 width=8 >) (actual time=0.455..11730.878 rows=6666668 loops=3) > >James Looks reasonable. Did you try it in other output formats - json/yaml? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services