Forum OpenACS Development: PostgreSQL 7.2.1 ?bug?

Collapse
Posted by Neophytos Demetriou on
Ok, I have tried this many times with PG-7.2.1 and I get the same results every time. I'm using PG-7.2.1 and tree_next_key(null,null) returns:
1000000000000000000000000000000

instead of:

00000000

So, I have looked more into this and to my surprise here's what I get:

# select 0<2^7;
 ?column?
----------
 f
(1 row)

# select 0<=2^7;
 ?column?
----------
 t
(1 row)

select 0<=(2^7-1);
 ?column?
----------
 t
(1 row)


# select 2^7 > 0;
 ?column?
----------
 t
(1 row)

 select 0::integer<(2^7)::integer;
 ?column?
----------
 t
(1 row) 

Could someone confirm this, please? To relate this with the tree_sortkey mechanism 0<2^7 is the condition used in the int_to_tree_key function. After personal communication with Don, I have changed acs-kernel/sql/postgresql/postgresql.sql from p_intkey < 2^7 to p_intkey < 128 so that we are sure.
Collapse
Posted by David Walker on
On my system. I just upgraded from 7.2 to 7.2.1.
template1=> select version();  
                           version  
-------------------------------------------------------------  
 PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.96  
(1 row)  
  
template1=> select 0<2^7;  
 ?column?  
----------  
 t  
(1 row)  
Collapse
Posted by Neophytos Demetriou on
I have tried this on a fresh pg-7.2.1 install. Maybe, it works for you due to the upgrade. Can someone else check it on a fresh install? David, have you restored your dumped data by using template1 or each database separately?
template1=# select version();
                           version                           
-------------------------------------------------------------
 PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.96



template1=# select 0 < 2^7;
 ?column? 
----------
 f
(1 row)
Collapse
Posted by David Walker on
I upgraded from 7.2 to 7.2.1 for the test.  I'll try it on a fresh
install and see what happens.
Collapse
Posted by Rob Storrs on
From a clean install of 7.2.1:
demo=> select version();
                           version
-------------------------------------------------------------
 PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.96
(1 row)

demo=> select 0 < 2^7;
 ?column?
----------
 t
(1 row)
Collapse
Posted by David Walker on
out of curiousity, what does "select 0=2^7" return?
Collapse
Posted by Neophytos Demetriou on
David:
# select 0=2^7;
 ?column? 
----------
 t
(1 row)
Very strange. I'll have to check my system. No idea what could be wrong.
Collapse
Posted by Rob Storrs on
template1=> select 0 < 2^7 as lt, 0 <= 2^7 as lte, 0 = 2^7 as 
equals, 0 >= 2^7 as gte, 0 > 2^7 as gt;
 lt | lte | equals | gte | gt
----+-----+--------+-----+----
 t  | t   | f      | f   | f
(1 row)

Looks good to me.
Collapse
Posted by Neophytos Demetriou on
Then, something is seriously messed up with my system. Anyone has any ideas of what could be wrong?
Collapse
Posted by David Walker on
what about "select 2^7"?

Same result in template1 database and in your openacs database?

Are you using any language encoding?  What OS and version are you
using?

Collapse
Posted by Neophytos Demetriou on
# select 2^7;
 ?column? 
----------
      128
(1 row)
Same result in template1 and other databases. Here's how I configure and start PG, respectively:

Installing PostgreSQL 7.2.1

cd /usr/local/src
        tar -xzvf postgresql-7.2.1.tar.gz
        cd postgresql-7.2.1
        ./configure --enable-multibyte=UNICODE --with-tcl --with-perl --enable-syslog
        gmake
        gmake install
        gmake install-all-headers
        mkdir /usr/local/pgsql/data
        useradd postgres
        passwd postgres
        chown postgres /usr/local/pgsql/data
        su - postgres
        export LANG=C
        /usr/local/pgsql/bin/initdb  --encoding unicode  -D /usr/local/pgsql/data
        /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 &        /usr/local/pgsql/bin/createdb test
        /usr/local/pgsql/bin/psql test
        /usr/local/pgsql/bin/dropdb test
        exit

Starting PG

/etc/rc.local
su -l postgres -c 'export LANG=C; /usr/local/pgsql/bin/postmaster -N 200 -B 1000 -o "-S 2000" -S -D /usr/local/pgsql/data '
I'm using RH-7.2. Only thing I can think of is that I messed something while trying to compile the new linux kernel with the grsecurity patches. I'm downloading RH-7.3, try to upgrade and see what comes out of it.
Collapse
Posted by David Walker on
Well if you're not opposed to trying other stuff you can "create
view myview as select 0<2^7" and then pg_dump that view and see how
postgres rewrites it.

On my system it is rewritten as
CREATE VIEW "myview" as SELECT (0 < (2 ^ 7));

Collapse
Posted by Neophytos Demetriou on
Same thing as your post (same result as well -- returns false). I'm still downloading RH-7.3. Hopefully, that would settle it.
Collapse
Posted by Don Baccus on
"--enable-multibyte=UNICODE" ... don't ask me why but I always worry when I see this ...

Can you folks who get the right answer confirm whether you're enabling unicode or not?

Collapse
Posted by David Walker on
I compiled and initdb'ed a Unicode postgres and got the right
answer.
Collapse
Posted by David Walker on
The inverse test of Neophytos compiling and testing a
non-Unicode postgres might be worthwhile as well.
Collapse
Posted by Andrei Popov on
I'd suggest running some of PG regression tests on that installation, here the full set of things above returns correct results:
select version();
                           version                           
-------------------------------------------------------------
 PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.96
(1 row)

select tree_next_key(null,null);
 tree_next_key 
---------------
 00000000
(1 row)

select 0<2^7;
 ?column? 
----------
 t
(1 row)

select 0=2^7;
 ?column? 
----------
 f
(1 row)

select 2^7;
 ?column? 
----------
      128
(1 row)
Collapse
Posted by Neophytos Demetriou on
Andrei thanks, I did that already and noticed that some of the tests fail. It seems that this is a problem with my RH installation. I've tried to upgrade my RH installation to 7.3 but it seems that there are some problems that hopefully I'll be able to tackle later this evening.