Re: [HACKERS] Patch (was: tough locale bug) - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: [HACKERS] Patch (was: tough locale bug)
Date
Msg-id 199903151444.JAA12654@candle.pha.pa.us
Whole thread Raw
In response to Patch (was: tough locale bug)  (Goran Thyni <goran@kirra.net>)
List pgsql-hackers
As I remember, this was fixed already, without your patch, right?


[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Goran Thyni wrote:
> > 3. text_lt('G','G\0xFF') this is not correct!
> > 
> > Case 3 work not work with strcoll(), in varstr_cmp().
> > If I change it to strcoll() to strncmp() it works as expected,
> > but it probably breaks sorting etc big time.
> 
> Here is a hack which solves the problem without breaking sorting AFAIK.
> I have read a lot of code, but has not found any cleaner way to fix
> this.
> A cleaner solution would be to find the highest char in locale charset
> but I found no portable way to do that, any pointers appriciated.
> 
> It is not a beauty but it works. 
> Please apply to -current since it fixes the bug, 
> unless someone has a better suggestion.
> 
>     best regards,
> -- 
> -----------------
> G_ran Thyni
> This is Penguin Country. On a quiet night you can hear Windows NT
> reboot!

> diff -cr cvs/pgsql/src/backend/utils/adt/varlena.c cvswork/pgsql/src/backend/utils/adt/varlena.c
> *** cvs/pgsql/src/backend/utils/adt/varlena.c    Mon Dec 14 07:01:37 1998
> --- cvswork/pgsql/src/backend/utils/adt/varlena.c    Sun Jan 31 16:32:52 1999
> ***************
> *** 496,528 ****
>   varstr_cmp(char *arg1, int len1, char *arg2, int len2)
>   {
>       int            result;
> !     char       *a1p,
> !                *a2p;
> ! 
>   #ifdef USE_LOCALE
> !     a1p = (unsigned char *) palloc(len1 + 1);
> !     a2p = (unsigned char *) palloc(len2 + 1);
> ! 
> !     memcpy(a1p, arg1, len1);
> !     *(a1p + len1) = '\0';
> !     memcpy(a2p, arg2, len2);
> !     *(a2p + len2) = '\0';
> ! 
> !     result = strcoll(a1p, a2p);
> ! 
> !     pfree(a1p);
> !     pfree(a2p);
> ! 
> ! #else
> ! 
> !     a1p = arg1;
> !     a2p = arg2;
> ! 
> !     result = strncmp(a1p, a2p, Min(len1, len2));
> !     if ((result == 0) && (len1 != len2))
> !         result = (len1 < len2) ? -1 : 1;
>   #endif
> ! 
>       return result;
>   }    /* varstr_cmp() */
>   
> --- 496,524 ----
>   varstr_cmp(char *arg1, int len1, char *arg2, int len2)
>   {
>       int            result;
> !     char       *a1p, *a2p;
>   #ifdef USE_LOCALE
> !     if ((int)arg2[len2 - 1] != -1)
> !       {
> !         a1p = (unsigned char *) palloc(len1 + 1);
> !         a2p = (unsigned char *) palloc(len2 + 1);
> !         memcpy(a1p, arg1, len1);
> !         *(a1p + len1) = '\0';
> !         memcpy(a2p, arg2, len2);
> !         *(a2p + len2) = '\0';
> !         result = strcoll(a1p, a2p);
> !         pfree(a1p);
> !         pfree(a2p);
> !       }
> !     else
>   #endif
> !       {
> !         a1p = arg1;
> !         a2p = arg2;
> !         result = strncmp(a1p, a2p, Min(len1, len2));
> !         if ((result == 0) && (len1 != len2))
> !         result = (len1 < len2) ? -1 : 1;
> !       }
>       return result;
>   }    /* varstr_cmp() */
>   


--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] Another speedup idea (two, even)
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] Postgres Speed or lack thereof