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 1lP6aX-00026e-J6 for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Mar 2021 16:42:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lP6aW-0003nW-Gg for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Mar 2021 16:42:32 +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 1lP6aW-0003nP-3c for pgsql-hackers@lists.postgresql.org; Wed, 24 Mar 2021 16:42:32 +0000 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lP6aT-0002Iw-8f for pgsql-hackers@postgresql.org; Wed, 24 Mar 2021 16:42:31 +0000 Received: by mail-il1-x134.google.com with SMTP id v3so21965103ilj.12 for ; Wed, 24 Mar 2021 09:42:28 -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=QzlTWqQXfwNV1VQRs8HB5ZFa3MZPvT+cRV9IqBPsDcw=; b=YAYD+IHpohfthVqLdsZZvTC9iz9WlfC7Oz6XUdQg6n8tzgvmVa3bwxSCtOjppUNuxt pM0cN5TVVbBW0QUDOV+jQUlB+5bLUoc2GxH8EFuPSQF0THXiDoLFBrKEIv5dx7Ded1LP hzEbLc6CCxVx5LUKUMzxZOz2/xbrS5G9Yj90qfmmhhKdfxxY1Y1VZKJMPJIgrOHjpVcz bctchKoJVlHX5xMKZ3EBR6jJtqho7Ghi7Kc1fSQfAV0mO8CJBdkknDuJykOdH0RBYL59 FiroKCw1o4biXlkc8XcrEkO96K0vly1xvA7n0UlnKB79lvs/iWgY39yCHSRWQVI/Olh1 pwQg== 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=QzlTWqQXfwNV1VQRs8HB5ZFa3MZPvT+cRV9IqBPsDcw=; b=swDwJBWMkydhQpMXLaNTzHsCr/Bf1TEM+qR3IGC67Gl0jFsIZiFG6TiADSl4Hd6itx cAhas62feD4Zae5F1jwrZZSp7aewSh7/IDdvhWfnYJI0q63Pnl7QQtr+e4vR1yPA+WzS 4voZN7OjAjc+Fe+zS7tQ0KdSzgRrrrcYnevq5gfSp9yWW5IDFCFVTM22L5jbGjzw0pj1 NvzJSnONvieqQ/bffiJWO4y6MZDuy6XRqLRdFXk/Ky/tlbyXokRdH08RAB7yePaPc/tY t4U4NoRyvmS58c89IdbmuxHsbOW7PJZ8taZ4etGECqjNIyaS49GLiFd8mqIQkqGMZk3S zbog== X-Gm-Message-State: AOAM532c3qhiO76sNoS9l0T0CvIYrC7w0UA/6hqWxgwPL1VUrBMaYjVf 2jhx9D21HHAL/BIfAs202J4R2Q== X-Google-Smtp-Source: ABdhPJxNd32qlCr+pj0sOqo3ojRxa3o2XM+la0ktR7D7hR1Aefi/aIwLBbCtH5geIABGEO9Pue8nEQ== X-Received: by 2002:a05:6e02:4a4:: with SMTP id e4mr3195662ils.114.1616604147536; Wed, 24 Mar 2021 09:42:27 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id g8sm1047676ile.44.2021.03.24.09.42.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Mar 2021 09:42:27 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 43BB380090D; Wed, 24 Mar 2021 11:42:26 -0500 (CDT) Date: Wed, 24 Mar 2021 11:42:26 -0500 From: Justin Pryzby To: Tomas Vondra Cc: Dean Rasheed , pgsql-hackers@postgresql.org Subject: Re: PoC/WIP: Extended statistics on expressions Message-ID: <20210324164226.GB15100@telsasoft.com> References: <9f6654b1-ca31-f979-0fe8-137683818273@enterprisedb.com> <20210324062446.GA28335@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210324062446.GA28335@telsasoft.com> 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 Wed, Mar 24, 2021 at 01:24:46AM -0500, Justin Pryzby wrote: > It seems like you're preferring to use pluralized "statistics" in a lot of > places that sound wrong to me. For example: > > Currently the first statistics wins, which seems silly. > I can write more separately, but I think this is resolved and clarified if you > write "statistics object" and not just "statistics". In HEAD:catalogs.sgml, pg_statistic_ext (the table) says "object": |Name of the statistics object |Owner of the statistics object |An array of attribute numbers, indicating which table columns are covered by this statistics object; But pg_stats_ext (the view) doesn't say "object", which sounds wrong: |Name of extended statistics |Owner of the extended statistics |Names of the columns the extended statistics is defined on Other pre-existing issues: should be singular "statistic": doc/src/sgml/perform.sgml: Another type of statistics stored for each column are most-common value doc/src/sgml/ref/psql-ref.sgml: The status of each kind of extended statistics is shown in a column Pre-existing issues: doesn't say "object" but I think it should: src/backend/commands/statscmds.c: errmsg("statistics creation on system columns is not supported"))); src/backend/commands/statscmds.c: errmsg("cannot have more than %d columns in statistics", src/backend/commands/statscmds.c: * If we got here and the OID is not valid, it means the statistics does src/backend/commands/statscmds.c: * Select a nonconflicting name for a new statistics. src/backend/commands/statscmds.c: * Generate "name2" for a new statistics given the list of column names for it src/backend/statistics/extended_stats.c: /* compute statistics target for this statistics */ src/backend/statistics/extended_stats.c: * attributes the statistics is defined on, and then the default statistics src/backend/statistics/mcv.c: * The input is the OID of the statistics, and there are no rows returned if should say "for a statistics object" or "for statistics objects" src/backend/statistics/extended_stats.c: * target for a statistics objects (from the object target, attribute targets Your patch adds these: Should say "object": + * Check if we actually have a matching statistics for the expression. + /* evaluate expressions (if the statistics has any) */ + * for the extended statistics. The second option seems more reasonable. + * the statistics had all options enabled on the original version. + * But if the statistics is defined on just a single column, it has to + /* has the statistics expressions? */ + /* expression - see if it's in the statistics */ + * column(s) the statistics depends on. Also require all + * statistics is defined on more than one column/expression). + * statistics is useless, but harmless). + * If there are no simply-referenced columns, give the statistics an auto + * Then the first statistics matches no expressions and 3 vars, + * while the second statistics matches one expression and 1 var. + * Currently the first statistics wins, which seems silly. + * [(a+c), d]. But maybe it's better than failing to match the + * second statistics? I can make patches for these (separate patches for HEAD and your patch), but I don't think your patch has to wait on it, since the user-facing documentation is consistent with what's already there, and the rest are internal comments. -- Justin