Vadim B. Mikheev wrote:
>
> Michael, do you use chars which >= 128 ?
> If yes and you havn't USE_LOCALE defined that problems
> with text-field come from nbtcompare.c:bttextcmp() - it uses
>
> char *ap, *bp;
> ^^^^
> (it was changed from unsigned near 20 May)
>
> while text funcs in varlena.c use unsigned char: UNSIGNED_CHAR_TEXT
> is defined. (It's big inconvenience that btree in one cases use
Reproduction:
File X generated from
#!/usr/local/bin/perl
for ($i = 1; $i <= 1000; $i++)
{
$val = rand (255);
next if $val < 32;
printf "%c\n", $val;
}
now:
vac=> create table t (x text);
CREATE
vac=> create index ti on t (x);
CREATE
vac=> copy t from '/home/postgres/My/OPTIMIZER/X';
FATAL 1:btree: items are out of order (leftmost 0, stack 3, update 1)
For 'char' field:
vac=> drop table t;
DROP
vac=> create table t (x char);
CREATE
vac=> create index ti on t (x);
CREATE
vac=> copy t from '/home/postgres/My/OPTIMIZER/X';
FATAL 1:btree: items are out of order (leftmost 0, stack 3, update 1)
If you create index AFTER copy (bulkload code):
vac=> create table t (x char);
CREATE
vac=> copy t from '/home/postgres/My/OPTIMIZER/X';
COPY
vac=> create index ti on t (x);
CREATE
: bulkload code use functions from utils/adt/*.c and so - all ok, but:
vac=> select count(*) from t where x = '9';
count
- -----
0
(1 row)
vac=> drop index ti;
DROP
vac=> select count(*) from t where x = '9';
count
- -----
5
(1 row)
I'm going to change all to 'unsigned' in nbtcompare.c
both for text and char types:
1. UNSIGNED_CHAR_TEXT is defined by default in config.h
for quite long time.
2. strncmp is used for char2, char8, ...
Vadim
------------------------------