Re: intarray internals - Mailing list pgsql-general

From Volkan YAZICI
Subject Re: intarray internals
Date
Msg-id 20060508193802.GA211@alamut
Whole thread Raw
In response to intarray internals  (Volkan YAZICI <yazicivo@ttnet.net.tr>)
Responses Re: intarray internals  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi,

[I'm trying to share some of my thoughts about intarray contrib module.
If this is the wrong way to achieve this, please warn me. (Should I
first get in touch with Teodor Sigaev and Oleg Bartunov?)]

[6]
_int_same() in _int_op.c looks like making some redundant sorting and
not taking advantage of sorted arrays while comparing each other. Here's
the related code piece:

SORT(a);
SORT(b);
na = ARRNELEMS(a);
nb = ARRNELEMS(b);
da = ARRPTR(a);
db = ARRPTR(b);

result = FALSE;

if (na == nb)
{
    result = TRUE;
    for (n = 0; n < na; n++)
        if (da[n] != db[n])
        {
            result = FALSE;
            break;
        }
}

IMHO, SORT() macro should be called after "if (na == nb)" block. (SORT()
doesn't remove duplicates.) Also, in the inner block, while comparing
two arrays, we can take advantage of sorting of arrays. While current
behaviour is like

if (A[0] == B[0] && A[1] == B[1] && ...)

we can replace it with sth like

if (A[0] == B[0] && A[  N] == B[  N] &&
    A[1] == B[1] && A[N-1] == B[N-1] &&
    ...)

Attached patch tries to implement both behaviours mentioned above and
some minor hacking for arrays of 1,2 and 3 items.


Regards.

Attachment

pgsql-general by date:

Previous
From: "George Pavlov"
Date:
Subject: Re: Using the REPLACE command to replace all vowels
Next
From: "Karl O. Pinc"
Date:
Subject: pg_restore duplicate key violations