Re: Unexpected (wrong?) result querying boolean partitioned table with NULL partition - Mailing list pgsql-hackers

From Richard Guo
Subject Re: Unexpected (wrong?) result querying boolean partitioned table with NULL partition
Date
Msg-id CAMbWs48x1jvE8Ab67Xbe8odLh96uLhw=DQi6oiQqBTvkyD7xnw@mail.gmail.com
Whole thread Raw
In response to Re: Unexpected (wrong?) result querying boolean partitioned table with NULL partition  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: Unexpected (wrong?) result querying boolean partitioned table with NULL partition
List pgsql-hackers

On Wed, Apr 12, 2023 at 7:13 PM David Rowley <dgrowleyml@gmail.com> wrote:
There's already code to effectively handle <> operators. Just the
PartClauseInfo.op_is_ne needs to be set to true.
get_matching_list_bounds() then handles that by taking the inverse of
the partitions matching the equality operator.

Effectively, I think that's the attached patch.

I think there is a thinko here.

+           switch (btest->booltesttype)
+           {
+               case IS_NOT_TRUE:
+                   *noteq = true;
+                   /* fall through */
+               case IS_TRUE:
+                   *outconst = (Expr *) makeBoolConst(true, false);
+                   break;
+               case IS_NOT_FALSE:
+                   *noteq = true;
+                   /* fall through */
+               case IS_FALSE:
+                   *outconst = (Expr *) makeBoolConst(false, false);
+                   break;
+               default:
+                   Assert(false); /* hmm? */
+                   return PARTCLAUSE_UNSUPPORTED;
+           }

The *outconst should be set to true in case IS_NOT_FALSE and set to
false in case IS_NOT_TRUE, something like:

            switch (btest->booltesttype)
            {
-               case IS_NOT_TRUE:
+               case IS_NOT_FALSE:
                    *noteq = true;
                    /* fall through */
                case IS_TRUE:
                    *outconst = (Expr *) makeBoolConst(true, false);
                    break;
-               case IS_NOT_FALSE:
+               case IS_NOT_TRUE:
                    *noteq = true;
                    /* fall through */
                case IS_FALSE:

Thanks
Richard

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Non-superuser subscription owners
Next
From: Peter Smith
Date:
Subject: Re: pg_upgrade and logical replication