equal() perf tweak - Mailing list pgsql-patches

From Neil Conway
Subject equal() perf tweak
Date
Msg-id 1067868034.3089.225.camel@tokyo
Whole thread Raw
Responses Re: equal() perf tweak  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
Currently, equal() does the following for List nodes:

case T_List:
{
    List       *la = (List *) a;
    List       *lb = (List *) b;
    List       *l;

    /*
     * Try to reject by length check before we grovel through
     * all the elements...
     */
    if (length(la) != length(lb))
        return false;
    foreach(l, la)
    {
        if (!equal(lfirst(l), lfirst(lb)))
            return false;
        lb = lnext(lb);
    }
    retval = true;
}
break;

This code is inefficient, however: length() requires iterating through
the entire list, so this code scans both lists twice. The attached patch
improves this by implementing equal() with a single scan of both lists.

-Neil


Attachment

pgsql-patches by date:

Previous
From: Jan Wieck
Date:
Subject: Re: bufmgr code cleanup
Next
From: Tom Lane
Date:
Subject: Re: bufmgr code cleanup