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 1kxhcz-0005nR-3M for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Jan 2021 02:35:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kxhcx-000862-53 for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Jan 2021 02:35:47 +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 1kxhcw-00085u-PI for pgsql-hackers@lists.postgresql.org; Fri, 08 Jan 2021 02:35:46 +0000 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kxhcr-00058j-IK for pgsql-hackers@postgresql.org; Fri, 08 Jan 2021 02:35:46 +0000 Received: by mail-io1-xd33.google.com with SMTP id i18so8360583ioa.1 for ; Thu, 07 Jan 2021 18:35:41 -0800 (PST) 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=RyBrY7rA+aPAzAyAoCjc8317we3SvicYN/ZZLFRdaGE=; b=mRXz0krDJSoP8doJGaAVrT/UcufCD13u0WTlvRsQCnZNmdQFY6bY88xcrR+N2XwvcZ zolXiyYHjuozf8SlfNqznePbFxPPc1O2T5+Ua8gy0j7zmrR4ucKs8YiIPdZGmZYtCCR5 NM41TZhCVoPYAntb2y7sWaiMT5YBsf4Orxsey2tf9uLdwWRS8FOe3fKfzTthyiATbB6P 6ornS0Sord9C9T8fWFg+v4CuKFxmsRDnc3O6LLyNaGzToC+jAVA8h1rvlZwoxhtXH9fM stJwfnBfRwx4q7hiPCChWvy0SrA8x5b9dURSWMg6PoTdILcW+G3BXlc5tUg14BvBZIKV jBMQ== 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=RyBrY7rA+aPAzAyAoCjc8317we3SvicYN/ZZLFRdaGE=; b=otnh10W2zumlEOFHxIAXkQc98kwKrKedoeTa2BUii7ZHimqC0oz+//lzOHGdJ077Ut UepqB+0uygE6gTczuJd57CU1X9SfDxHXvikNh9JJPciuURAZpmCDLeQLZ9ggDfGQunvZ u0wa3+EDBS1SDvS3ekoR0/Az85AldPS1V7EIAePwop4NxAANrR0WBswsTnEv9/ClvjRJ 50aBZRU3gEO4J4Uo9X9w/RcjOTH83FFrM7m+yc3WGiWtcZwYIZl+iA4QO9vI9IJVfpdx IbjsFXcdHr2ofZ9BGuAOa7frf5br2bz5L1pSPLHD7wZo4M0Ml9BmzeXrY2MnpZbMZWuH cOEA== X-Gm-Message-State: AOAM533Jw4g8PkAJMo+jcCxApjXdmXi7SjhbvjrNDWFGWsp7x8h38rOa Ddjo5TVi9KpU4f2hXwytl94NLg== X-Google-Smtp-Source: ABdhPJwSgEwkpgIiOEBVVBdyZXM/zGUS5n7h5OvLv8qCisnTVqDI+R3YXKkb2LB48nm3wsOiCT5b+A== X-Received: by 2002:a5e:db4b:: with SMTP id r11mr3710931iop.148.1610073339754; Thu, 07 Jan 2021 18:35:39 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id m75sm6164312ill.15.2021.01.07.18.35.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jan 2021 18:35:38 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id AFD5880095C; Thu, 7 Jan 2021 20:35:37 -0600 (CST) Date: Thu, 7 Jan 2021 20:35:37 -0600 From: Justin Pryzby To: Tomas Vondra Cc: Dean Rasheed , pgsql-hackers@postgresql.org Subject: Re: PoC/WIP: Extended statistics on expressions Message-ID: <20210108023537.GA19743@telsasoft.com> References: <4a2918bb-49b0-ccd5-3af7-f7795941a6ad@enterprisedb.com> <958870c8-65e0-31b1-4591-b0b10e807dd9@enterprisedb.com> <329203a4-7cad-a0e3-d5a8-ce70872c8156@enterprisedb.com> <2567ae7e-e1dd-48b5-054d-ed6ff81c0335@enterprisedb.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: Precedence: bulk On Fri, Jan 08, 2021 at 01:57:29AM +0100, Tomas Vondra wrote: > Attached is a patch fixing most of the issues. There are a couple > exceptions: In the docs: + — at the cost that its schema must be extended whenever the structure + of statistics pg_statistic changes. should say "of statistics *IN* pg_statistics changes" ? + to an expression index. The full variant allows defining statistics objects + on multiple columns and expressions, and pick which statistics kinds will + be built. The per-expression statistics are built automatically when there "and pick" is wrong - maybe say "and selecting which.." + and run a query using an expression on that column. Without the remove "the" ? + extended statistics, the planner has no information about data + distribution for reasults of those expression, and uses default *results + estimates as illustrated by the first query. The planner also does + not realize the value of the second column fully defines the value + of the other column, because date truncated to day still identifies + the month). Then expression and ndistinct statistics are built on The ")" is unbalanced + /* all parts of thi expression are covered by this statistics */ this + * GrouExprInfos, but only if it's not known equal to any of the existing Group + * we don't allow specifying any statistis kinds. The simple variant statistics + * If no statistic type was specified, build them all (but request Say "kind" not "type" ? + * expression is a simple Var. OTOH we check that there's at least one + * statistics matching the expression. one statistic (singular) ? + * the future, we might consider + */ consider ??? +-- (not it fails, when there are no simple column references) note? There's some remaining copy/paste stuff from index expressions: errmsg("statistics expressions and predicates can refer only to the table being indexed"))); left behind by evaluating the predicate or index expressions. Set up for predicate or expression evaluation Need an EState for evaluation of index expressions and /* Compute and save index expression values */ left behind by evaluating the predicate or index expressions. Fetch function for analyzing index expressions. partial-index predicates. Create it in the per-index context to be * When analyzing an expression index, believe the expression tree's type -- Justin