Обсуждение: Use opresulttype instead of calling SearchSysCache1() in match_orclause_to_indexcol()

Поиск
Список
Период
Сортировка

Use opresulttype instead of calling SearchSysCache1() in match_orclause_to_indexcol()

От
Tender Wang
Дата:
Hi,

While working on another issue, I stepped into match_orclause_to_indexcol().
I found below codes:

/* Only the operator returning a boolean suit the transformation. */
if (get_op_rettype(opno) != BOOLOID)
      break;

In get_op_rettype, it calls SearchSysCache1() to get oprresult of Form_pg_operator.
I think we can use the opresulttype of OpExpr to achieve the same effect, but there is no need to call SearchSysCache1().

Although this would not improve performance,  it can save some CPU time.
Any thoughts?

--
Thanks,
Tender Wang
Вложения

Re: Use opresulttype instead of calling SearchSysCache1() in match_orclause_to_indexcol()

От
Aleksander Alekseev
Дата:
Hi Tender,

> Although this would not improve performance,  it can save some CPU time.
> Any thoughts?

The patch looks correct to me. The correctness can also be rechecked like this:

```
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -3372,6 +3372,9 @@ match_orclause_to_indexcol(PlannerInfo *root,
                /* Only the operator returning a boolean suit the
transformation. */
                if (get_op_rettype(opno) != BOOLOID)
                        break;
+               else {
+                       Assert(subClause->opresulttype == BOOLOID);
+               }
```

-- 
Best regards,
Aleksander Alekseev



Tender Wang <tndrwang@gmail.com> writes:
> While working on another issue, I stepped into match_orclause_to_indexcol().
> I found below codes:

> /* Only the operator returning a boolean suit the transformation. */
> if (get_op_rettype(opno) != BOOLOID)
>       break;

I don't understand what purpose this check serves at all.
We are looking at an arm of an OR clause, so it had better
yield boolean.

If anything, this is actively wrong, because for example it'd
reject a polymorphic operator that yields boolean in-context.

In general, this code looks like a mess.  There are a lot of
Asserts that might be okay in development but probably should
not have got committed, and the comments need work.

            regards, tom lane