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 1hNzys-00022v-H4 for pgsql-hackers@arkaria.postgresql.org; Tue, 07 May 2019 13:18:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hNzyr-0005v4-77 for pgsql-hackers@arkaria.postgresql.org; Tue, 07 May 2019 13:18:01 +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 1hNzyq-0005rK-Ml for pgsql-hackers@lists.postgresql.org; Tue, 07 May 2019 13:18:00 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hNzym-0003DQ-Ug for pgsql-hackers@postgresql.org; Tue, 07 May 2019 13:17:59 +0000 Received: by mail-wm1-x342.google.com with SMTP id y197so19992671wmd.0 for ; Tue, 07 May 2019 06:17:56 -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=NGQag88bU3pzxFQyhxbTWS+FZvtcy4tpcA657kooaa0=; b=wGBfJYnccidlI80rEExBkoAIPnXiZ7B1QCEytnIwpkO0ecNPCX8bJJqPVZ3O2zmZKM Ul8C/tvtx4jD50sTUCs8D8po4Lv2EGrGUs8gJqhMIPLf3qcakop20DfF5ySWhT1xNnI3 JHMJHmKG14OAKLpKFAsPCAV5igNqdNRWVqmUd/TOowmxihvXTPnbHvSZz+V79Ol1Ch1m gn/klCxnlMuDiJn1uDLCRSGcuagjNZPhB6m0gkVNlzH9T3xUfyHoy9lGR92tCkmL0H0j XNDjXyKMKAjXG2X6Ix5+dGYW6g/Db6KheRcIMtlE0oyKnOE9qRG7F3J/ObQPFI+tsaaR 2P1g== 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=NGQag88bU3pzxFQyhxbTWS+FZvtcy4tpcA657kooaa0=; b=KNjDDcuT8vXHDBjLBZyPCJZkeuP6RahAFDUs2FXAIhyKissnxqczFsUxpqGUX2WXzb wDEXHnK/jFYKUSD/R9FmwZDJgtJeP35ZH2ylgSwYXeffcoQeAgT9vDP0d0Fl14UKSBS2 R4imM30yPljPGk8IT9FT4NPjBoh5ux6gXpSR4MWr7XcfLyfXJFZvI0rUkhCGLQNrY9U7 9K8UigcGVmneoGmhUsGygtbkPj73f4v82vnMEAm4ptRuybKPGTS9uBsgG4BaqFjni9Ed SLBDfcLPZDkCXo9lObBMhOgk1RsYM0QVljW1VZ5UFwR10dgRw4BRuIBAD6tz14tv62MQ D72A== X-Gm-Message-State: APjAAAXvrrhSe0PnSAZLWd9BCTzLUbMxNPxWJCrCI+M8Uj2Gg0uxkOCj H55RWTzTY0r+Ccl/kDMwACCDEQ== X-Google-Smtp-Source: APXvYqwHbbyT9IMpr6ijOIdDXJ6OcIEa6qU20I12rajhGsc9nFjGZFcN3ss72Nlnx732SJ8bvC9tgA== X-Received: by 2002:a7b:cb11:: with SMTP id u17mr20706388wmj.55.1557235075175; Tue, 07 May 2019 06:17:55 -0700 (PDT) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id o8sm19369915wra.4.2019.05.07.06.17.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 07 May 2019 06:17:44 -0700 (PDT) Date: Tue, 7 May 2019 15:17:42 +0200 From: Tomas Vondra To: Tom Lane Cc: Thomas Munro , Melanie Plageman , hackers Subject: Re: accounting for memory used for BufFile during hash joins Message-ID: <20190507131742.nixczzyyyuuoig7m@development> References: <20190504003414.bulcbnge3rhwhcsh@development> <20190507031511.lvp6bqn2e5dpsnga@development> <27902.1557199108@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <27902.1557199108@sss.pgh.pa.us> User-Agent: NeoMutt/20180716-1444-295967-dirty List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, May 06, 2019 at 11:18:28PM -0400, Tom Lane wrote: >Tomas Vondra writes: >> Do we actually check how many duplicates are there during planning? > >Certainly that's part of the planner's cost estimates ... but it's >only as good as the planner's statistical knowledge. > I'm looking at the code, and the only place where I see code dealing with MCVs (probably the best place for info about duplicate values) is estimate_hash_bucketsize in final_cost_hashjoin. That's not quite what I had in mind - I was thinking more about something along the lines "See the larget group of duplicate values, disable hash join if it can't fit into work_mem at all." Of course, if the input estimates are off, that may not work too well. It would certainly not help the query failing with OOM, because that was a case of severe underestimate. Or did you mean some other piece of code that I have missed. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services