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 1gUITk-0005s1-0D for pgsql-performance@arkaria.postgresql.org; Tue, 04 Dec 2018 21:43:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gUITi-0003xD-Cx for pgsql-performance@arkaria.postgresql.org; Tue, 04 Dec 2018 21:43:38 +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 1gUITh-0003x2-V2 for pgsql-performance@lists.postgresql.org; Tue, 04 Dec 2018 21:43:38 +0000 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUITe-0001Oq-My for pgsql-performance@lists.postgresql.org; Tue, 04 Dec 2018 21:43:36 +0000 Received: by mail-qk1-x743.google.com with SMTP id n12so10623150qkh.11 for ; Tue, 04 Dec 2018 13:43:34 -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:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=Ruxk6I+4z2dQf1HV9rvDJGIqfp3KLUDXVocyz2/FZuM=; b=UPfeapA8s+wLxz78Zj1qGrsro4DID+QbzQ+VT5G43QCtjgPKIApXqjlkY09krtxBPT jy0HA2VcfWRtjzd2bpVkpEe7Q8apX7zptxQHO7KQPidPchlH0WXWiMtvwZGWStxZDhYB pgm6yMgyuqK4TnG+n/J5WFPAs0SwKCN4QpI0YTNZbytKWKDeCq+Fr8dT7LXgvTl7yaPw tJOeN+HyMNl10FCRR2cZ5LeKYfEjBKCD54lSo17m6/HmoRpqkE5pnjHvUXRNcxLHVjaD AVTq3aZBFewj369/thc3mq6cVP32QFOQDyXOA+jak+UvL8cw25GUpk6fiR2FifWKmb37 KauA== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Ruxk6I+4z2dQf1HV9rvDJGIqfp3KLUDXVocyz2/FZuM=; b=nN0W1pJN2aU4m3YOOzoaMJKq9EMedzvWZ8WNxzwO2iLpwe/n/WVJgLcPttVXjpnaZc f0PGoRglZcSmp5sRPGK6LMK4sdoHhUjKZZJMm5pJody8I3UXu2Tw72fK2J76ZfpRa6MC NtmmYme2X5NXNmqtkuMRlFhS4SeFRbPnhixKLf3scFSXticSR+OEM4lCi2UANhE8FwYU PsptCw7eb1cOuLPX+70/hXhnJCGrO6aeSCl4hxAbTkS5lgukem3Y8Z0Eut+cP71BduCJ DQUf1yaR+bcpMb+/E3D0EPB2TN4Uz8+Fc8KuwYsYb8/CxpnKCvgzlrFFdPx1y7Kiwe6N vJKg== X-Gm-Message-State: AA+aEWY4Re1AyN7NISgqsfkiQqnEvEaTSyV9wIkRIPI8ku+wHx8GaGxO CtKKjIvI/0KSyxol5nlngbT8IA== X-Google-Smtp-Source: AFSGD/UgTPvVblY0qXrRe/6O8AlXYfWO3L1SIqm0NNlt2JxlmYw1OsU7NeSOvAjBlmUClkn0Ht2vaA== X-Received: by 2002:a37:93c3:: with SMTP id v186mr20311429qkd.285.1543959813546; Tue, 04 Dec 2018 13:43:33 -0800 (PST) Received: from alvin.alvh.no-ip.org ([201.186.80.75]) by smtp.gmail.com with ESMTPSA id q54sm11977245qtb.64.2018.12.04.13.43.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Dec 2018 13:43:32 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 47848422; Tue, 4 Dec 2018 18:43:31 -0300 (-03) Date: Tue, 4 Dec 2018 18:43:31 -0300 From: Alvaro Herrera To: Justin Pryzby Cc: Sanyo Moura , jeff.janes@gmail.com, David Rowley , Robert Haas , Ashutosh Bapat , pgsql-performance@lists.postgresql.org Subject: Re: Query with high planning time at version 11.1 compared versions 10.5 and 11.0 Message-ID: <20181204214331.o7ljrfjja4jkkiau@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20181128030129.GG30707@telsasoft.com> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk So, the slowness in this test seems to come from add_child_rel_equivalences() and bms_overlap() therein, according to perf (mine and Justin's) ... apparently we end up with a lot of equivalence class members. I added a debugging block to spit out the number of ECs as well as the number of members in each (after creating table "precio" and about a thousand partitions), and I got progressively slower lines the last of which says WARNING: 4 classes: 2000, 1999, 1999, 999001, so for some reason we produced quadratic number of EC members, and we bms_overlap all that stuff over and over a number of times. This code seems to come from partitionwise join. Now, the query is a bit silly; it puts table "precio" four times in the range table. (thanks http://sqlformat.darold.net/) CREATE TABLE precio(fecha timestamp, pluid int, loccd int, plusalesprice int) PARTITION BY RANGE (fecha); SELECT format('CREATE TABLE public.precio_%s PARTITION OF public.precio (PRIMARY KEY (fecha, pluid, loccd) ) FOR VALUES FROM (''%s'')TO(''%s'')', i, a, b) FROM (SELECT '1990-01-01'::timestam p+(i||'days')::interval a, '1990-01-02'::timestamp+(i||'days')::interval b, i FROM generate_series(1,999) i)x \gexec EXPLAIN SELECT l_variacao.fecha, l_variacao.loccd, l_variacao.pant, l_variacao.patual, max_variacao.var_max FROM ( SELECT p.fecha, p.loccd, p.plusalesprice patual, da.plusalesprice pant, a bs (p.plusalesprice - da.plusalesprice) AS var FROM precio p, ( SELECT p.fecha, p.plusalesprice, p.loccd FROM precio p WHERE p.fecha BETWEEN '2017-03-01' AND '2017-03-02' AND p.pluid = 2) da WHERE p.fecha BETWEEN '2017-03-01' AND '2017-03-02' AND p.pluid = 2 AND p.loccd = da.loccd AND p.fecha = da.fecha) l_variacao, ( SELECT max(abs(p.plusalesprice - da.plusalesprice)) AS var_max FROM precio p, ( SELECT p.fecha, p.plusalesprice, p.loccd FROM precio p WHERE p.fecha BETWEEN '2017-03-01' AND '2017-03-02' AND p.pluid = 2) da WHERE p.fecha BETWEEN '2017-03-01' AND '2017-03-02' AND p.pluid = 2 AND p.loccd = da.loccd AND p.fecha = da.fecha) max_variacao WHERE max_variacao.var_max = l_variacao.var; -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services