Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1amp2R-0003JJ-5R for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Apr 2016 20:54:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1amp2Q-0002kE-2z for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Apr 2016 20:54:26 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1amp12-0000Cc-JO for pgsql-hackers@postgresql.org; Sun, 03 Apr 2016 20:53:00 +0000 Received: from mail-lf0-x22e.google.com ([2a00:1450:4010:c07::22e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1amp0y-0001yn-Lz for pgsql-hackers@postgresql.org; Sun, 03 Apr 2016 20:52:59 +0000 Received: by mail-lf0-x22e.google.com with SMTP id c126so23291372lfb.2 for ; Sun, 03 Apr 2016 13:52:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=+OTZzRvWbHKjj2ebS0OkUlarCcoPnIMi1Pin5JD/8Ug=; b=CBp8WcjTn7ThCQy1h6N0LhJ7vl5pPqvQwHgqeyB3gPPOM2YqftkWUijpMTrbsQssiv LI5UfuYX1o364VCvdG04vJPEF4DJY8qCcPTGEeLGxgMyX9v8z5TAw3p1Dab6zkoXTrNH A2ptc/FFGdjYkcqOvHujTDJa7wt9mUzwPBX7+PtIeODg0PMnYD5QRR2rZgUfKUWzDTNQ ybyi8nYLk6d4HtZCN+HF+dukdjrALScaJx8V0/GHeVDzn2BJPFUY3FinLeJp3SJH35Wb BlxRXF156L/bNyHTHwQGtyIQpbXuoqD6Pgu8XxROy/H4akgOFFD3GJtyhdR99sEEwTvc sMfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=+OTZzRvWbHKjj2ebS0OkUlarCcoPnIMi1Pin5JD/8Ug=; b=JoPp5ouJn0LUraSbvR1g1aLn+S6F8RT+Tlm1FvvLWhP5niRNt/Kz9HbQ07DPD8Ac/k TaVQbF1CpILvkjFKSE8aFsZCH8mD/voylx9NHa92VOBmRLBSN9dz+rzrZI97kVAtPTN3 48cWE9c5j4oj1KsetbzXsmVrg7sd2ERtoXH+91vPALQXd0/Wb3yahEXXY8JUI2haDfKd sNHRYT5lNgp3ATb7qfXUCXHvBl4SmLdJvMMlrU8We9sU3cjDgdH0DGWpxym+N2SPJ4jA r0ek+HCE1ImPlW3BW7EX8OrutrLC8Q4TdfMfxWtGyTS4AyRQ5pPqeCPu//1MlJ0aYY7N GLqA== X-Gm-Message-State: AD7BkJIPl5Rjs+lzfJSb2ZY3v2Q16Sos05TiCjCEl/BAgqyDu46/U4STEoe9iaaIDdvIgECY/k/vfVymzViNP9iy+x+2wpt3JD/btDeJSWMekmWYbeGhxprTAzegXqGoDlkagcdV5MzgLWVIO2dHrLzOQuItwbnIKSZAimhZUaL46o0Br+W1nfyfmOaEVlrRCumB28T/TbOz X-Received: by 10.194.236.3 with SMTP id uq3mr16255892wjc.119.1459716775271; Sun, 03 Apr 2016 13:52:55 -0700 (PDT) Received: from [10.137.2.17] (ip-78-45-216-26.net.upcbroadband.cz. [78.45.216.26]) by smtp.gmail.com with ESMTPSA id lz5sm25593074wjb.5.2016.04.03.13.52.53 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 03 Apr 2016 13:52:54 -0700 (PDT) Subject: Re: Using quicksort for every external sort run To: Peter Geoghegan References: <56FB25BB.6070805@2ndquadrant.com> <7142bf2a-9460-b549-61f3-8cb32a3209f9@2ndquadrant.com> <27716590-56b5-baf0-71ee-d27f309c1acc@2ndquadrant.com> Cc: Pg Hackers From: Tomas Vondra Message-ID: <267c57d1-b0fc-aa9b-ecb6-cadfe1a36d8d@2ndquadrant.com> Date: Sun, 3 Apr 2016 22:52:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Thunderbird/46.0a2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 04/03/2016 09:41 PM, Peter Geoghegan wrote: > Hi Tomas, ... >> 3) replacement_sort_mem GUC >> >> I'm not quite sure what's the plan with this GUC. It was useful for >> development, but it seems to me it's pretty difficult to tune it in practice >> (especially if you don't know the internals, which users generally don't). > > I agree. > >> So I think we should either remove the GUC entirely, or move it to the >> developer section next to trace_sort (and removing it from the conf). > > I'll let Robert decide what's best here, but I see your point. > > Side note: trace_sort actually is documented. It's a bit weird that we > have those TRACE_SORT macros at all IMV. I think we should rip those > out, and assume every build enables TRACE_SORT, because that's > probably true anyway. What do you mean by documented? I thought this might be a good place is: http://www.postgresql.org/docs/devel/static/runtime-config-developer.html which is where trace_sort is documented. > > I do think that replacement selection could be put to good use for > CREATE INDEX if the CREATE INDEX utility command had a "presorted" > parameter. Specifically, an implementation of the "presorted" idea > that I recently sketched [1] could do better than any presorted > replacement selection case we've seen so far because it allows the > implementation to optimistically create the index on-the-fly (if that > isn't possible, throw an error), without a second pass over tuples > sorted on tape. Nothing needs to be stored on a tape/temp file *at > all*; the only thing that is stored externally is the index itself. > But this patch doesn't add that feature, which can be worked on > without the user needing to know about replacement_sort_mem in 9.6. > > So, I'm not in favor of ripping out the replacement selection code, > but think it could make sense to effectively disable it entirely for > the time being (with some developer feature to turn it back on for > testing). In general, I share your misgivings about the new GUC, > though. OK. > >> I'm wondering whether 16MB default is not a bit too much, actually. As >> explained before, that's not the amount of cache we should expect per >> process, so maybe ~2-4MB would be a better default value? > > The obvious presorted case is where we have a SERIAL column, but as I > mentioned even that isn't helped by RS. Moreover, it will be > significantly hurt with a default maintenance_work_mem of 64MB. Your > int4 CREATE INDEX cases clearly show this. > >> BTW couldn't we tune the value automatically for each sort, using the >> pg_stats.correlation for the sort keys, when available (increasing the >> replacement_sort_mem when correlation is close to 1.0)? Wouldn't that >> improve at least some of the regressions? > > Maybe, but that seems hard. That information isn't conveniently > available to the executor/tuplesort, and as we've seen with CREATE > INDEX int4 cases, it's far from clear that we'll win even when there > definitely is presorted input. Replacement selection needs more than a > simple correlation to win, so you'll end up building a cost model with > many new problems if this is to work. Sure, that's non-trivial and definitely not a 9.6 material. I'm also wondering whether we need to do choose replacement_sort_mem at planning time, or whether it could be done in the executor based on actually observed data ... regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers