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 1l1HFp-00041Q-53 for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Jan 2021 23:14:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l1HFo-0007RF-1T for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Jan 2021 23:14:40 +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 1l1HFn-0007R7-LP for pgsql-hackers@lists.postgresql.org; Sun, 17 Jan 2021 23:14:39 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l1HFk-0003VM-5X for pgsql-hackers@postgresql.org; Sun, 17 Jan 2021 23:14:39 +0000 Received: by mail-ed1-x530.google.com with SMTP id bx12so1555203edb.8 for ; Sun, 17 Jan 2021 15:14:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=8wxp3ZCfYErcgJ/Vls3tpXyuP3OFSk3dQjdktkCZqyQ=; b=JngLr1qiAZ0ufRx6wifPfBU9gnSpIDBuxDAKPw0XVnhIwCalsQB9kKftZ6djSXgecf /drHiOIuobWuTmsgfFaHnteOh7blpe9cQ4TLBX6T1Vss8JQ09XZC4cyMvJZK+05Vh395 IFHzw1541mcoEwHszgRxixCvgPt7pvot7nfYc7b2hV+X7uuGXe7AiK5yiJpimAwgbyKQ ch0djIslpGdp3LEfguBbYpdwK0Hic3zv31AVucmoofYri+3X8SrM1X1AYJL3sJhmripn moq3MDZ3JvxM7G74+Treb09m3mt+hpdc0tcXrofYUr7mWK5sPu1tpOwZ+1jCJbtnYGOG xmbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=8wxp3ZCfYErcgJ/Vls3tpXyuP3OFSk3dQjdktkCZqyQ=; b=pf21cp6ApwJOuLJtPtBL1t5yfjGJQYn95l2keCQiib5/Bqz6eSptUxiuAFQnBjWE4l 6zZAlU192l4xjsYZqpVtrCr8QdBfinJGuseIaw0YIMlStsM9MAO5FRY3v3BWHAE2ZffO Uc7Z9T1ci+UrY7Okz/LWELv0dMaj7UEWYs8SfuTSAEs2oLQCyt9VQnAbf2bjx1LxdZUZ gfd3cmrTLYQxM7hsgh4WuGG4mJxiwiFf2G0UWyBHjJ56wERi+CjVMJH0btkbgABBzg8d 2MIqfEuGgRStfZbYXMJcy+NcPrYbRei69kCdgqVpyMbJFxvwmogMDEmTzdGzWXTlKGvz JuTg== X-Gm-Message-State: AOAM530C8HZMsoQLSlKlKpiL1xb93WCHskAO9/1vuojxHeKyrSjugzIs z4hVbRMllUd5CpYi16iV/2g5qU2bTMVyg7ab2ukoE/qzAKxhVY4MPJVilwp+fno8d1dmew9ypzE uzBrNCdaXCzosposidXHsY4MhRuRDEkIk6oIJdeVdVq8W5Cmuv45Jh5Z50m4jiwIUmx4XRNSP8+ vNqoe+2Xpl8aycAuONAs2vf11loiAeroGAkjAKKa84vD+5DH1YOUbGuikpezciZP4XrYuylaiH7 gus3mo6Ye9lBIWAo0++vYC0BoFu9txgqMo5pg== X-Google-Smtp-Source: ABdhPJwgO4MFk+Yg5x8dB9jJcSkhc5QvH+ygkP29MAwfqrFr1CwTflsBgXAP9mS/tOHqz/uN0OOc2g== X-Received: by 2002:aa7:c547:: with SMTP id s7mr17044275edr.240.1610925274493; Sun, 17 Jan 2021 15:14:34 -0800 (PST) Received: from [10.137.0.20] (ip-86-49-253-127.net.upcbroadband.cz. [86.49.253.127]) by smtp.gmail.com with ESMTPSA id b7sm8743877ejz.4.2021.01.17.15.14.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 17 Jan 2021 15:14:33 -0800 (PST) Subject: Re: PoC/WIP: Extended statistics on expressions To: Zhihong Yu Cc: Justin Pryzby , Dean Rasheed , PostgreSQL-development References: <329203a4-7cad-a0e3-d5a8-ce70872c8156@enterprisedb.com> <2567ae7e-e1dd-48b5-054d-ed6ff81c0335@enterprisedb.com> <20210108023537.GA19743@telsasoft.com> <5305f9cf-3927-06c4-cd5b-e46cbc58bc7f@enterprisedb.com> <20210116232208.GB8560@telsasoft.com> <2f2a3b3b-93e4-723f-144e-bc21f10d6b61@enterprisedb.com> From: Tomas Vondra Message-ID: <01a2e09f-843a-824b-42c4-4d31d173b4a7@enterprisedb.com> Date: Mon, 18 Jan 2021 00:14:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/17/21 3:55 AM, Zhihong Yu wrote: > Hi, > +    * Check that only the base rel is mentioned.  (This should be dead code > +    * now that add_missing_from is history.) > +    */ > +   if (list_length(pstate->p_rtable) != 1) > > If it is dead code, it can be removed, right ? > Maybe. The question is whether it really is dead code. It's copied from transformIndexStmt so I kept it for now. > For statext_mcv_clauselist_selectivity: > > +                   // bms_free(list_attnums[listidx]); > > The commented line can be removed. > Actually, this should probably do list_free on the list_exprs. > +bool > +examine_clause_args2(List *args, Node **exprp, Const **cstp, bool > *expronleftp) > > Better add some comment for examine_clause_args2 since there > is examine_clause_args() already. > Yeah, this probably needs a better name. I have a feeling this may need a refactoring to reuse more of the existing code for the expressions. > +   if (!ok || stats->compute_stats == NULL || stats->minrows <= 0) > > When would stats->minrows have negative value ? > The typanalyze function (e.g. std_typanalyze) can set it to negative value. This is the same check as in examine_attribute, and we need the same protections I think. > For serialize_expr_stats(): > > +   sd = table_open(StatisticRelationId, RowExclusiveLock); > + > +   /* lookup OID of composite type for pg_statistic */ > +   typOid = get_rel_type_id(StatisticRelationId); > +   if (!OidIsValid(typOid)) > +       ereport(ERROR, > > Looks like the table_open() call can be made after the typOid check. > Probably, but this failure is unlikely (should never happen) so I don't think this makes any real difference. > +       Datum       values[Natts_pg_statistic]; > +       bool        nulls[Natts_pg_statistic]; > +       HeapTuple   stup; > + > +       if (!stats->stats_valid) > > It seems the local arrays can be declared after the validity check. > Nope, that would be against C99. > +           if (enabled[i] == STATS_EXT_NDISTINCT) > +               ndistinct_enabled = true; > +           if (enabled[i] == STATS_EXT_DEPENDENCIES) > +               dependencies_enabled = true; > +           if (enabled[i] == STATS_EXT_MCV) > > the second and third if should be preceded with 'else' > Yeah, although this just moves existing code. But you're right it could use else. > +ReleaseDummy(HeapTuple tuple) > +{ > +   pfree(tuple); > > Since ReleaseDummy() is just a single pfree call, maybe you don't need > this method - call pfree in its place. > No, that's not possible because the freefunc callback expects signature void (*)(HeapTupleData *) and pfree() does not match that. thanks -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company