Re: intarray internals

Поиск
Список
Период
Сортировка
От Volkan YAZICI
Тема Re: intarray internals
Дата
Msg-id 20060508193802.GA211@alamut
обсуждение исходный текст
Ответ на intarray internals  (Volkan YAZICI <yazicivo@ttnet.net.tr>)
Ответы Re: intarray internals  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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.

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: "George Pavlov"
Дата:
Сообщение: Re: Using the REPLACE command to replace all vowels
Следующее
От: "Karl O. Pinc"
Дата:
Сообщение: pg_restore duplicate key violations