Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpHLu-0000KL-Is for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Sep 2016 16:04:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bpHLt-0000Lf-Va for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Sep 2016 16:04:58 +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 1bpHLs-0000Ku-GS for pgsql-hackers@postgresql.org; Wed, 28 Sep 2016 16:04:56 +0000 Received: from mail-lf0-x22d.google.com ([2a00:1450:4010:c07::22d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bpHLn-00054T-Fp for pgsql-hackers@postgresql.org; Wed, 28 Sep 2016 16:04:55 +0000 Received: by mail-lf0-x22d.google.com with SMTP id g62so57666234lfe.3 for ; Wed, 28 Sep 2016 09:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=NavTtYJMO/3FzoQDlXqoZkV8oMwXNko3qLatMGq0MNM=; b=FPXaP81tjfXqL9KQn/fKnl2YVJX3OlG+RLkiS9RArDqpieKYuH+cTE3BfVbYsoPnNR hF2IxRMYnBGDEMvfJvIFSZw0031ObPQ7ElI0/G8X4L2R3P6TKSMpbK1x7fsR2+NTKQ13 FGUdOpv/5o/pdjkGHlFjf2UOKOo4L6tycZuZenrNAF6W3a/X7/8m0JhX3hUYWcmT1jQP UiTbs1a3JleiVvWP4CQ4KIz9rHabtpghoelf159KR56yeQ9WnQuU1+jJzbk51wkmHDUF k60VR45PfHgVDyvh4RMm4HSKHopPoey5X1p9FUl2b5z2wR2uhpVAK3sV5NiRbQ7YKULr lQeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=NavTtYJMO/3FzoQDlXqoZkV8oMwXNko3qLatMGq0MNM=; b=YC8jxYWuBcwMYrNop2SYymRdMyb6qSSunXa3vWLv1OW0rrqmr4mF+H4gUCTKt90cUR oF8/MbXmsCk83gzajYvHOmD00fKeTfMpr3SApspxzxZH8dBgcpgccrERzsDobxi0DM+Z IAYhMVAYQEhDV9ViaE5G8mPS5PRkhRJTQEpVxAfr+lcpGNoTzd9OIwY5FUl2Pko7N5tp VzbIRI4CGXsIBdxm4p+huJJkayduxdweO8rOKIvkxF1OspQ0htzT22lquRjWgDjWT9DC tLJOtewUyN6XdD9Xm8tG2Rbt/8xmnf6cLDnGWOuYqtYoJkzcggRoUQB4jgXWUQ0kyT4r b1xA== X-Gm-Message-State: AA6/9Rk7tu0PgUlKc9u04hYtF479zlvqwpKzFsW5NzcFPORG4Uz96wMVglzF6kHKkBerbQ== X-Received: by 10.25.155.15 with SMTP id d15mr2417041lfe.121.1475078690594; Wed, 28 Sep 2016 09:04:50 -0700 (PDT) Received: from [192.168.1.111] (dsl-hkibrasgw1-58c38f-82.dhcp.inet.fi. [88.195.143.82]) by smtp.gmail.com with ESMTPSA id u137sm1365328lja.16.2016.09.28.09.04.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Sep 2016 09:04:49 -0700 (PDT) Subject: Re: Tuplesort merge pre-reading To: Peter Geoghegan References: <95f5a75d-b6ad-f175-57f2-6e32f745e908@iki.fi> <2a1b4071-5f4f-4dce-e74b-1c5575c11608@iki.fi> <41adf9c3-0659-16e2-e06e-494826b0c969@iki.fi> <49817174-c2b6-1378-3d3e-285d270f8fcc@iki.fi> <7f7d8271-112c-66a0-8194-8568091e98ad@iki.fi> <1541ef84-c2e4-26b6-03a3-19d22589caa2@iki.fi> Cc: Claudio Freire , pgsql-hackers From: Heikki Linnakangas Message-ID: <0c0b80fc-9dea-c031-ce51-2781edefad4d@iki.fi> Date: Wed, 28 Sep 2016 19:04:48 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.2.0 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 09/28/2016 06:05 PM, Peter Geoghegan wrote: > On Thu, Sep 15, 2016 at 9:51 PM, Heikki Linnakangas wrote: >> I don't think it makes much difference in practice, because most merge >> passes use all, or almost all, of the available tapes. BTW, I think the >> polyphase algorithm prefers to do all the merges that don't use all tapes >> upfront, so that the last final merge always uses all the tapes. I'm not >> 100% sure about that, but that's my understanding of the algorithm, and >> that's what I've seen in my testing. > > Not sure that I understand. I agree that each merge pass tends to use > roughly the same number of tapes, but the distribution of real runs on > tapes is quite unbalanced in earlier merge passes (due to dummy runs). > It looks like you're always using batch memory, even for non-final > merges. Won't that fail to be in balance much of the time because of > the lopsided distribution of runs? Tapes have an uneven amount of real > data in earlier merge passes. How does the distribution of the runs on the tapes matter? >> + usedBlocks = 0; >> + for (tapenum = 0; tapenum < state->maxTapes; tapenum++) >> + { >> + int64 numBlocks = blocksPerTape + (tapenum < remainder ? 1 : 0); >> + >> + if (numBlocks > MaxAllocSize / BLCKSZ) >> + numBlocks = MaxAllocSize / BLCKSZ; >> + LogicalTapeAssignReadBufferSize(state->tapeset, tapenum, >> + numBlocks * BLCKSZ); >> + usedBlocks += numBlocks; >> + } >> + USEMEM(state, usedBlocks * BLCKSZ); > > I'm basically repeating myself here, but: I think it's incorrect that > LogicalTapeAssignReadBufferSize() is called so indiscriminately (more > generally, it is questionable that it is called in such a high level > routine, rather than the start of a specific merge pass -- I said so a > couple of times already). You can't release the tape buffer at the end of a pass, because the buffer of a tape will already be filled with data from the next run on the same tape. - Heikki -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers