Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ljRgr-0006AA-2I for pgsql-hackers@arkaria.postgresql.org; Wed, 19 May 2021 19:17:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ljRgp-00009X-PP for pgsql-hackers@arkaria.postgresql.org; Wed, 19 May 2021 19:17:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ljRgp-00009O-Da for pgsql-hackers@lists.postgresql.org; Wed, 19 May 2021 19:17:07 +0000 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ljRgk-0004yC-E9 for pgsql-hackers@lists.postgresql.org; Wed, 19 May 2021 19:17:06 +0000 Received: by mail-ot1-x333.google.com with SMTP id g7-20020a9d12870000b0290328b1342b73so4893499otg.9 for ; Wed, 19 May 2021 12:17:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-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=hLPyTemRorLUycFrb0Pa8uGuJgI4bh/ympJ2wFAkE1w=; b=yokywPAElQtAPODvMH+jzd/SpMLXNVQ93oYI+ZtQKpQRkvuNEk9UaMki8Emldr3+x7 CnDK2b2oqhg7I2RQD0EQ+RpRCQb4MEmd3DAARxNh/2ll381ArscvR13N7mUcPALhoUwF hX+JmOhP4eWofw1qrYJfraz+VKfpg5nHj8VTifFjNOCth+cirSj7uMN8G4WqIZOBrAXE /vUbe+t656gDSC7R0EVURGHrVgiaP09/fb74MatrRCCwrvBYhihwEO76VELlcxp6Il+o 0QZ6Z2XNtzHn7cAHedvKlCzmNdDgAUnbKQKQy6Z1ZOZHzfrsUl0gI1UPszkinbhq8hJF J5PQ== 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=hLPyTemRorLUycFrb0Pa8uGuJgI4bh/ympJ2wFAkE1w=; b=brCRZpnVCFSCiQOTFh2Ih+EI5YAp0gI+0EkpvWeTXHNr9UbZbmWIdKIY30jB0ARwJb YKq5ZNSvIIFD0irzKSkiwM82G46ffIIe8I8TgvcjTXIL0nAFECvXf8ufK9VPBtwVfeXh Xs3ntYIiVdvFXkVg1KT3O6pKYVV5v88ObeYJ/VjhiH371xBRgcIuykyprj6g2Ud/Ifpt 6wiW+zptT67Vr2iMh6NRFwIGlABm2dvw2p2tniqOhzUH9zI2Czne6MZeKPeuPxJoPLUX K+grR+iDWjy6btmplCOsuuk1y2YLsTLmFjExMgXAFo+tdvTe1VVyryzEihmunupAusdB j5WA== X-Gm-Message-State: AOAM5328mKiJYzIRGGCgWe19+o+4XVwQNCgUem3DsKJ7lQcirIzORaVE WxEgsXC1YU7KClh21ByP3AV/xQ== X-Google-Smtp-Source: ABdhPJzjr9moiXdiptWOClbjiXiQ+zNfADf47ZOPAH1EzHBR6zMpAKfOtoxEBYZwlDkPcijVp9XK7g== X-Received: by 2002:a9d:1ee3:: with SMTP id n90mr806267otn.305.1621451820295; Wed, 19 May 2021 12:17:00 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id n193sm106485oig.49.2021.05.19.12.16.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 May 2021 12:16:59 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 9008F8008F8; Wed, 19 May 2021 14:16:58 -0500 (CDT) Date: Wed, 19 May 2021 14:16:58 -0500 From: Justin Pryzby To: Nitin Jadhav Cc: Robert Haas , Zhihong Yu , pgsql-hackers@lists.postgresql.org Subject: Re: Removed extra memory allocations from create_list_bounds Message-ID: <20210519191658.GA3496@telsasoft.com> References: <20210516170029.GB373@telsasoft.com> <20210517150310.GG373@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, May 18, 2021 at 01:49:12PM -0400, Robert Haas wrote: > I see that you have made a theoretical argument for why this should be > good for performance, but it would be better to have some test results > that show that it works out in practice. Sometimes things seem like > they ought to be more efficient but turn out to be less efficient when > they are actually tried. I see this as a code cleanup more than an performance optimization. I couldn't see a measurable difference in my tests, involving CREATE TABLE and SELECT. I think some of my patches could *increase* memory use, due to power-of-two allocation logic. I think it's still a good idea, since it doesn't seem to be the dominant memory allocation. On Thu, May 20, 2021 at 12:21:19AM +0530, Nitin Jadhav wrote: > > I see that you have made a theoretical argument for why this should be > > good for performance, but it would be better to have some test results > > that show that it works out in practice. Sometimes things seem like > > they ought to be more efficient but turn out to be less efficient when > > they are actually tried. > > After this I tried to create 10 partitions and observed the time taken > to execute. Here is the data for 'with patch'. > > postgres@34077=#select 'create table t_' || i || ' partition of t for > postgres'# values in (' || i || ');' > postgres-# from generate_series(10001, 10010) i > postgres-# \gexec I think you should be sure to do this within a transaction, without cassert, and maybe with fsync=off full_page_writes=off. > If we observe above data, we can see the improvement with the patch. > The average time taken to execute for the last 10 partitions is. It'd be interesting to know which patch(es) contributed to the improvement. It's possible that (say) patch 0001 alone gives all the gain, or that 0002 diminishes the gains. I think there'll be an interest in committing the smallest possible patch to realize the gains, to minimize code churn an unrelated changes. LIST and RANGE might need to be checked separately.. > With respect to memory usage, AFAIK the allocated memory gets cleaned > during deallocation of the memory used by the memory context. So at > the end of the query, we may see no difference in the memory usage but > during the query execution it tries to get less memory than before. You can check MAXRSS (at least on linux) if you enable log_executor_stats, like: \set QUIET \\ SET client_min_messages=debug; SET log_executor_stats=on; DROP TABLE p; CREATE TABLE p(i int) PARTITION BY LIST(i); CREATE TABLE pd PARTITION OF p DEFAULT; SELECT format('CREATE TABLE p%s PARTITION OF p FOR VALUES IN (%s)', a,a) FROM generate_series(1,999)a;\gexec \\ SELECT; -- Justin