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 1j5ciX-00060Y-PN for pgsql-hackers@arkaria.postgresql.org; Sat, 22 Feb 2020 21:53:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j5ciW-0006v8-5T for pgsql-hackers@arkaria.postgresql.org; Sat, 22 Feb 2020 21:53:44 +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 1j5ciV-0006v0-FT for pgsql-hackers@lists.postgresql.org; Sat, 22 Feb 2020 21:53:43 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j5ciS-00075X-59 for pgsql-hackers@lists.postgresql.org; Sat, 22 Feb 2020 21:53:41 +0000 Received: by mail-wr1-x442.google.com with SMTP id z7so5953693wrl.13 for ; Sat, 22 Feb 2020 13:53:39 -0800 (PST) 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=8fVxEEEUoXBNepGVolLY6NzBWThsnz6yPPcBAUQO1/Y=; b=0XqMD1YArm00lCpBZUk+Y2hXtOmlF3q4Ht4i5qzkA0ZwgKDLX5uHcsPaaDi5VWPC1l ea8jmW4fRcLKo/9kcouwOvGI0Eud1ChYdFOe7yW3N2/JhguVcv0fmq5M8PBmd+I72UMJ bQrNheXWt4bOJPKzUPHkHXBkPHb5YQrVhyYB2IV36jf4vBeCLCevdyw5bqtkWJpO63DR mHcchE1H82a1XescCy+UqCRIbN5Zk8GCbawcgmZPNYpPJzrbFPlmN+uyOtTtszz6vV0C wR/HjImOhp4XpwdNjeeNcxfUu+ZU4mYT0j7kIFCVB7AWQOi/kShyv0AZH25OYgk8JBcu 8kdw== 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=8fVxEEEUoXBNepGVolLY6NzBWThsnz6yPPcBAUQO1/Y=; b=B3tjPs+9ihyHLV0Mi6qlVJ9m4e/Pa1iZl5dPJuOW4vBofJYPE4uddJrIJOOTfbvhpK jSUJ8OTXfQIExokxqCQN3aTSBhnyMlhfM/Ct/4SdubBC/7esuKPoQMbxLNVwrDJgU7Y5 AtS2r2C2LL/lbgK2MxlRXdZ2z9hnhgZrVJFe9s/DfWei19BiaDcRtrQxiBhLSeWsqaC/ 2txMhJxgfdZsMlV/XA8hkad/qL3foDxZ6/EIJI7bcju8i94A+UXD9lLQ+7EYS8bngV7R FpE8KuqD/f892BrL3EOToFKwY//QfZzlZi8TOjUU3YWXtlQl/nOY+pqwQxffvZkPdyNX OsYQ== X-Gm-Message-State: APjAAAVBBUeHaF1hfHg3R3RpueplGCzDIRYGbgDUctErz+VBu+N3QPcl bTR22+3uk/yyEbbUfJ28O7J1Fg== X-Google-Smtp-Source: APXvYqxB8HA/YSAw23AqH5sGdtzCtkK4um4VARbhxQ7WYszzfyrmx0mi1bGLjo85wbobfZOpl4LxKw== X-Received: by 2002:adf:f803:: with SMTP id s3mr55822132wrp.7.1582408418475; Sat, 22 Feb 2020 13:53:38 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id f1sm10412036wro.85.2020.02.22.13.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Feb 2020 13:53:37 -0800 (PST) Date: Sat, 22 Feb 2020 22:53:35 +0100 From: Tomas Vondra To: Justin Pryzby Cc: Andres Freund , pgsql-hackers@lists.postgresql.org, Jeff Janes Subject: Re: explain HashAggregate to report bucket and memory stats Message-ID: <20200222215335.bu4kky7el4nccls5@development> References: <20200103161925.GM12066@telsasoft.com> <20200203145301.53mozz7gcdaklnjc@alap3.anarazel.de> <20200216000220.GF31889@telsasoft.com> <20200216175307.GJ31889@telsasoft.com> <20200219201037.GA21433@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200219201037.GA21433@telsasoft.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I've started looking at this patch, because I've been long missing the information about hashagg hash table, so I'm pleased someone is working on this. In general I agree it may be useful to add simila information to other nodes using a hashtable, but IMHO the hashagg bit is the most useful, so maybe we should focus on it first. A couple of comments after an initial review of the patches: 1) explain.c API The functions in explain.c (even the static ones) follow the convention that the last parameter is (ExplainState *es). I think we should stick to this, so the new parameters should be added before it. For example instead of static void ExplainNode(PlanState *planstate, List *ancestors, const char *relationship, const char *plan_name, ExplainState *es, SubPlanState *subplanstate); we should do e.g. static void ExplainNode(PlanState *planstate, SubPlanState *subplanstate, List *ancestors, const char *relationship, const char *plan_name, ExplainState *es); Also, the first show_grouping_sets should be renamed to aggstate to make it consistent with the type change. 2) The hash_instrumentation is a bit inconsistent with what we already have. We have Instrumentation, JitInstrumentation, WorkerInstrumentation and HashInstrumentation, so I suggest we follow the same patter and call this HashTableInstrumentation or something like that. 3) Almost all executor nodes that are modified to include this new instrumentation struct also include TupleHashTable, and the data are essentially about the hash table. So my question is why not to include this into TupleHashTable - that would mean we don't need to modify any executor nodes, and it'd probably simplify code in explain.c too because we could simply pass the hashtable. It'd also simplify e.g. SubPlanState where we have to add two new fields and make sure to update the right one. 4) The one exception to (3) is BitmapHeapScanState, which does include TIDBitmap and not TupleHashTable. And then we have tbm_instrumentation which "fakes" the data based on the pagetable. Maybe this is a sign that TIDBitmap needs a slightly different struct? Also, I'm not sure why we actually need tbm_instrumentation()? It just copies the instrumentation data from TIDBitmap into the node level, but why couldn't we just look at the instrumentation data in TIDBitmap directly? 5) I think the explain for grouping sets need a rething. Teh function show_grouping_set_keys was originally meant to print just the keys, but now it's also printing the hash table stats. IMO we need a new function printing a grouping set info - calling show_grouping_set_keys to print the keys, but then also printing the extra hashtable info. 6) subplan explain I probably agree the hashtable info should be included in the subplan, not in the parent node. Otherwise it's confusing, particularly when the node has multiple subplans. The one thing I find a bit strange is this: explain (analyze, timing off, summary off, costs off) select 'foo'::text in (select 'bar'::name union all select 'bar'::name); QUERY PLAN ---------------------------------------------- Result (actual rows=1 loops=1) SubPlan 1 Buckets: 4 (originally 2) Null hashtable: Buckets: 2 -> Append (actual rows=2 loops=1) -> Result (actual rows=1 loops=1) -> Result (actual rows=1 loops=1) (7 rows) That is, there's no indication why would this use a hash table, because the "hashed subplan" is included only in verbose mode: explain (analyze, verbose, timing off, summary off, costs off) select 'foo'::text in (select 'bar'::name union all select 'bar'::name); QUERY PLAN ---------------------------------------------------------------------------------- Result (actual rows=1 loops=1) Output: (hashed SubPlan 1) SubPlan 1 Buckets: 4 (originally 2) Memory Usage Hash: 1kB Memory Usage Tuples: 1kB Null hashtable: Buckets: 2 Memory Usage Hash: 1kB Memory Usage Tuples: 0kB -> Append (actual rows=2 loops=1) -> Result (actual rows=1 loops=1) Output: 'bar'::name -> Result (actual rows=1 loops=1) Output: 'bar'::name (10 rows) Not sure if this is an issue, maybe it's fine. But it's definitely strange that we only print memory info in verbose mode - IMHO it's much more useful info than the number of buckets etc. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services