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 1nCuGT-0005eL-5a for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Jan 2022 02:11:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nCuGR-0007OZ-V7 for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Jan 2022 02:11:55 +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 1nCuGR-0007OQ-GV for pgsql-hackers@lists.postgresql.org; Thu, 27 Jan 2022 02:11:55 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nCuGN-0007C4-Ab for pgsql-hackers@lists.postgresql.org; Thu, 27 Jan 2022 02:11:54 +0000 Received: by mail-pj1-x1035.google.com with SMTP id h12so1405129pjq.3 for ; Wed, 26 Jan 2022 18:11:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OJVAxxHGmYo9w+zd1X8AD5ywN7E9ESdYP9h6AG2iVGo=; b=otj5dnZC/T1ifktobZy8f7zYlgGu6cM6C0c4Zy6jkAvtD7HyIk7P17dvhjaMmW0fcR p71ISiCmt1pwsrWEUW5wPkPjNChD5U/pAp8bII5Svo1FTr5nT7lJDb1c8PdUGCesZQBt Jm8gu7Xj/5H+TEiajPKMfResA1sPdCj7qVcQaiuNuEdbPitTFmccgdCJkrqIk/aYwnPW f6PdI7OWoml83c05N0hmkRdoH3YjqW994aEQGyKIt9BNWgYTQVu/faGKBGjlSQosqFk/ c2mZS/vvruBOV7Q/h2JN7vYJUmWOJRakSnrMsVyOeNqc0VG7YUxcRVLjYy9pWBlkAzbw gRlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OJVAxxHGmYo9w+zd1X8AD5ywN7E9ESdYP9h6AG2iVGo=; b=HSY1zQOGE/eqZsb1HlZvVokqcmnSeLshaVzW6MYRpXKAyC3fmnTbJPPwsgXCUsi5o5 7TFcxiCc3lDnfehBAouTvZ4HOVRfz5jmLqLzm3KIw6SVuybgzsPzGL6/Rf3hL576qirB nF3RGwTc1Ig9huZylBccRff+y/kJ1Ao77m477Dmm7CaoO3AiTQQNg5r5eqUHBFpDeL/3 HLDpslfqEoiB6VeevKqcK6bIJ9AEEMacviAM2jKiHOrcFxVrf3Cyu2Nb83CvdShodboW xAnJvl7Ib60jrDZ3jczjU7Y71ABM1OzDZEmSqfrdyiXpGqQYFGVM/RfjykH+TBaVmCxH 3pYQ== X-Gm-Message-State: AOAM533dQ19mGuWWhfl1hi7KvpcCUq6Ed+WNU9h2/05pQNkXb16XkK2Z zekJE+GuQUYLZy9B4wgP/v/cl2UT34WGcjkzVTE= X-Google-Smtp-Source: ABdhPJzDAqx3N+fXPXrWDPnAaMc8McOwe6D1IUEOxUxD/aD7GpxnDSdo2LY9Xi8HDHAAA9lOhFEODISO/81DYnXgKWQ= X-Received: by 2002:a17:902:ec81:: with SMTP id x1mr1202906plg.109.1643249510048; Wed, 26 Jan 2022 18:11:50 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amit Langote Date: Thu, 27 Jan 2022 11:11:33 +0900 Message-ID: Subject: Re: Question on partition pruning involving stable operator: timestamptz_ge_date To: TAO TANG Cc: pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Thu, Jan 27, 2022 at 10:28 AM TAO TANG wrote: > the plan shows all the partitions are pruned, but in gdb tracing, it shows that > the pruning happens in ExecInitAppend, and during planning stage pg does not > prune any partitions. this is because in function match_clause_to_partition_key > do not handle the case for STABLE operator: > > if (op_volatile(opno) != PROVOLATILE_IMMUTABLE) > { > context->has_mutable_op = true; > > /* > * When pruning in the planner, we cannot prune with mutable > * operators. > */ > if (context->target == PARTTARGET_PLANNER) > return PARTCLAUSE_UNSUPPORTED; > } > > the procs for timestamptz compare with date are STABLE: > > proname | provolatile > ----------------------+------------- > timestamptz_lt_date | s > timestamptz_le_date | s > timestamptz_eq_date | s > timestamptz_gt_date | s > timestamptz_ge_date | s > timestamptz_ne_date | s > timestamptz_cmp_date | s > (7 rows) > > but in ExecInitAppend call perform_pruning_base_step which do not consider the STABLE > property of the cmpfn. > > so I have serveral questions: > 1) why in planning the function volatility is considered but not in execInitAppend; The value of a STABLE expression can change based on runtime parameters, so while it is guaranteed to remain the same during a particular execution of a plan in which it is contained, it can change across multiple executions of that plan (if it is cached, for example). So the planner cannot assume a particular value of such expressions when choosing partitions to add to the plan, because each execution of the plan (each may run in a separate transaction) can produce different values. ExecInitAppend(), on the other hand, can assume a particular value when choosing partitions to initialize, because the value is fixed for a particular execution during which it runs. > 2) why timestamptz_xxx_date is STABLE not IMMUTABLE; Because calculations involving timestamptz values can produce different results dependkng on volatile settings like timezone, datestyle, etc. -- Amit Langote EDB: http://www.enterprisedb.com