Re: Recent updates - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: Recent updates
Date
Msg-id 199807151631.MAA12199@candle.pha.pa.us
Whole thread Raw
In response to Re: Recent updates  ("Thomas G. Lockhart" <lockhart@alumnus.caltech.edu>)
List pgsql-hackers
> > What does 'select null order by 1;' do now?
>
> postgres=> select null order by 1;
> ERROR:  type id lookup of 0 failed
>
> Darn. That doesn't touch the UNION code, so will need to look elsewhere
> I guess.
>
> > I have renamed the append struct names just now as part of an EXPLAIN
> > fix.  Should not affect you.
>
> OK.
>
>                     - Tom
>

It is from here:

    #2  0x9aca9 in typeidType (id=0) at parse_type.c:69
    #3  0x99d19 in oper (opname=0x8ce13 "<", ltypeId=0, rtypeId=0,
        noWarnings=0 '\000') at parse_oper.c:614
    #4  0x95a18 in transformSortClause (pstate=0x129f50, orderlist=0x130650,
        sortlist=0x0, targetlist=0x130690, uniqueFlag=0x0) at parse_clause.c:330
    #5  0x7daed in transformSelectStmt (pstate=0x129f50, stmt=0x2dfb90)
        at analyze.c:802
    #6  0x7cb99 in transformStmt (pstate=0x129f50, parseTree=0x2dfb90)
        at analyze.c:190
    #7  0x7c91c in parse_analyze (pl=0x130670, parentParseState=0x0)
        at analyze.c:76

Looks easy to fix.  The code is:

    /* check for exact match on this operator... */
    if (HeapTupleIsValid(tup = oper_exact(opname, ltypeId, rtypeId, NULL, NULL,$
    {
    }
    /* try to find a match on likely candidates... */
    else if (HeapTupleIsValid(tup = oper_inexact(opname, ltypeId, rtypeId, NULL$
    {
    }
    else if (!noWarnings)
    {
        elog(ERROR, "Unable to find binary operator '%s' for types %s and %s",
             opname, typeTypeName(typeidType(ltypeId)), typeTypeName(typeidType$
    }

It can't find operators for NULL, and is bombing when trying to print
the error message.  I think we need to handle this query properly,
because some sql's generated by other programs will auto-order by all
the fields.  I think your fix that you did with sort perhaps can be done
here.

But actually, the call is coming from transformSortClause(), so parhaps
you can do a NULL test there and prevent oper() from even being called.

Glad you are back on-line.

--
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)

pgsql-hackers by date:

Previous
From: "Thomas G. Lockhart"
Date:
Subject: Re: Recent updates
Next
From: Andreas Zeugswetter
Date:
Subject: AW: [HACKERS] "internal error" triggered by EXISTS()