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 1leOmK-0001gn-3C for pgsql-hackers@arkaria.postgresql.org; Wed, 05 May 2021 21:09:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1leOmI-00066x-SX for pgsql-hackers@arkaria.postgresql.org; Wed, 05 May 2021 21:09:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1leOmI-00064m-Fj for pgsql-hackers@lists.postgresql.org; Wed, 05 May 2021 21:09:54 +0000 Received: from mail-il1-x136.google.com ([2607:f8b0:4864:20::136]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1leOmE-0004Tf-AF for pgsql-hackers@lists.postgresql.org; Wed, 05 May 2021 21:09:53 +0000 Received: by mail-il1-x136.google.com with SMTP id v13so2927103ilj.8 for ; Wed, 05 May 2021 14:09:50 -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:mime-version:content-disposition :user-agent; bh=yetKgw5Vd8kwsbVwTlRUKcskri7R2to2aDrb4Gj4Ykc=; b=zhWoVNFxsfQwRx4TjzvEO4LYiiDtBQEQO+7+11AJ+A6/u3hbk+RZmorr2YnY5HV/KC dlOcgR6+TcKr9TESDoyxoXShYzANNpFqo4KszywgD4mPfjnZlKIq/T40jmV7LVeVGG2V 2csk28nyMXodnZblfMvS2iSI0BVv9TyeWWYitqk977UC+W+SpsgeU9Cxl6Wv82bUov1R bZNGDJqgCB//YbYGXHnUM3G1vaBOHUUX5XeuJLY7RLqRl6SsFzyvpybVq1mf7wi1bHKi T7v/zUje9MxWPBLPWx3VwUu4WkvY39xwBd/nO7A6RjpuR2se0leIZCE+5NFdZASSa0fb FzrQ== 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:user-agent; bh=yetKgw5Vd8kwsbVwTlRUKcskri7R2to2aDrb4Gj4Ykc=; b=brlid4ApGQ/Wt/5b8id9yjMfMD/d7dbm0YXd+P+ZEbbq9GFfiUYGHQKSiEKWVWa3mk TjW11WeM29UzOmmr/uJ/YBLU1KxneI7SPNjZajWjk+VdKQ7WQLwp3hUy7WrGzO2JE9AI Kd3yIJgp+fT4dFP/HAoDwChodiYLQ3/KRVjX+ZQESlNfMf4pl035XhNRzueyS6sNaZa4 rJb81Rm4aqsRL3pPxuzUNGyoDX7HyEzoTu2e6RKc6iWeXn+G5Lb33g4wMJJaIec1eLCz Ky8RzH12EJibDo4auu5R01uGV6gZHmBz3ZRwfnmVMzw/dEln3gtg++5vekiDOsNbM7+7 DtiQ== X-Gm-Message-State: AOAM531ykvYhNRfc3kdex/sdj6HW8mRq+/FxXK0+J0jIYYI/nrhE2V5o 5GWv/PPYTZHW86aDVD49ZlCodBnag1HiTQ== X-Google-Smtp-Source: ABdhPJy0enCy6W3NEkuqYQkGyUaNesGLnnQvytUnEvyzJQj61H/pciEBsOdURvAicJ8iJDB3JtwXtQ== X-Received: by 2002:a92:c26a:: with SMTP id h10mr851886ild.294.1620248989477; Wed, 05 May 2021 14:09:49 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id d7sm175545ioc.37.2021.05.05.14.09.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 May 2021 14:09:48 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id ABB4B8008C1; Wed, 5 May 2021 16:09:47 -0500 (CDT) Date: Wed, 5 May 2021 16:09:47 -0500 From: Justin Pryzby To: Tomas Vondra Cc: pgsql-hackers@lists.postgresql.org Subject: cache lookup failed for statistics object 123 Message-ID: <20210505210947.GA27406@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="aX6oBa4COn3eIhlv" Content-Disposition: inline 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 --aX6oBa4COn3eIhlv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Per sqlsmith. postgres=# SELECT pg_get_statisticsobjdef_expressions(123); ERROR: cache lookup failed for statistics object 123 postgres=# \errverbose ERROR: XX000: cache lookup failed for statistics object 123 LOCATION: pg_get_statisticsobjdef_expressions, ruleutils.c:1762 The expectation is that sql callable functions should return null rather than hitting elog(). In the 003 patch, I wonder if this part should be updated, too: | ... which can greatly improve query plans that use the expression index. It can improve queries even that don't use the index, right ? Say, if a query has f(x) = 11, and the MCV list for the expression shows that 50% of the table has f(x)=11, then the query might decide to *not* use an index scan. -- Justin --aX6oBa4COn3eIhlv Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Return-NULL-rather-than-elog-ERROR-for-sql-callable-.patch" From 6dec09300e4ad6cc7977acbfee9db7087420a9b5 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Wed, 5 May 2021 04:29:00 -0500 Subject: [PATCH 1/3] Return NULL rather than elog(ERROR) for sql-callable function --- src/backend/utils/adt/ruleutils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 0a4fa93d01..881e8ec03d 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -1759,9 +1759,9 @@ pg_get_statisticsobjdef_expressions(PG_FUNCTION_ARGS) statexttup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statextid)); if (!HeapTupleIsValid(statexttup)) - elog(ERROR, "cache lookup failed for statistics object %u", statextid); + PG_RETURN_NULL(); - /* has the statistics expressions? */ + /* Does the stats object have expressions? */ has_exprs = !heap_attisnull(statexttup, Anum_pg_statistic_ext_stxexprs, NULL); /* no expressions? we're done */ -- 2.17.0 --aX6oBa4COn3eIhlv Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0002-Comment-typos-extended-stats-a4d75c86b-and-518442c7f.patch" From ede54e64cf5e2249fe6910d6f2c0de177a0edb9b Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Tue, 27 Apr 2021 07:57:50 -0500 Subject: [PATCH 2/3] Comment typos: extended stats a4d75c86b and 518442c7f --- src/backend/parser/parse_utilcmd.c | 2 +- src/backend/statistics/extended_stats.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index 9dd30370da..eb9e63f4a8 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -1943,7 +1943,7 @@ generateClonedExtStatsStmt(RangeVar *heapRel, Oid heapRelid, * simply append them after simple column references. * * XXX Some places during build/estimation treat expressions as if they - * are before atttibutes, but for the CREATE command that's entirely + * are before attributes, but for the CREATE command that's entirely * irrelevant. */ datum = SysCacheGetAttr(STATEXTOID, ht_stats, diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index 7e11cb9d5f..5e53783ea6 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -1796,7 +1796,7 @@ statext_mcv_clauselist_selectivity(PlannerInfo *root, List *clauses, int varReli continue; /* - * Now we know the clause is compatible (we have either atttnums + * Now we know the clause is compatible (we have either attnums * or expressions extracted from it), and was not estimated yet. */ -- 2.17.0 --aX6oBa4COn3eIhlv Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0003-Mention-statistics-objects.patch" From e64e4b3d206d76ed8bbd5345798e0d35958759bd Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Fri, 23 Apr 2021 09:15:40 -0500 Subject: [PATCH 3/3] Mention statistics objects Previously mentioned at 20210423025012.GI7256@telsasoft.com --- doc/src/sgml/maintenance.sgml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/src/sgml/maintenance.sgml b/doc/src/sgml/maintenance.sgml index ee6113926a..de7fd75e1c 100644 --- a/doc/src/sgml/maintenance.sgml +++ b/doc/src/sgml/maintenance.sgml @@ -330,7 +330,8 @@ Also, by default there is limited information available about - the selectivity of functions. However, if you create an expression + the selectivity of functions. However, if you create a statistics + object or an expression index that uses a function call, useful statistics will be gathered about the function, which can greatly improve query plans that use the expression index. -- 2.17.0 --aX6oBa4COn3eIhlv--