A crashing query

A crashing query

Post by Mario Jorge Nunes Fili » Thu, 29 Mar 2001 21:02:17



Hello

Today I present myself before you with a vudu like question...

Here's the problem:

We're running several PostgreSQL databases in several different servers
(also with different PG versions :( ).

In one of our on-line systems we connect to the "local" database and a
"remote" database. The connection to the remote database was always ok,
without any kind of problems, but yesterday, out of the blue, one of the
query's (the most important one) started to crash the remote server.

The tables on the remote server are like this:

si=> \d lecciona
Table    = lecciona
+----------------------------------+----------------------------------+-------+
|              Field               |              Type                |
Length|
+----------------------------------+----------------------------------+-------+
| classe                           | text not null default ( 'ects' ) |
var |
| curso                            | int4                             |
4 |
| disciplina                       | int4                             |
4 |
| ano_lectivo                      | int4                             |
4 |
| docente                          | text not null                    |
var |
+----------------------------------+----------------------------------+-------+
Index:    lecciona_mkey

There are several other tables descendand of this one. Some of them have
no extra fields, some of them do.

Yestrday a new class was added (this is the only difference from before,
and since then the following query no longer works:

 select distinct disciplina from lecciona* l where l.docente='$id' and
l.ano_lectivo<= $ano_lectivo and l.classe in ('lecciona','responsvel')
and not exists (select 1 from lecciona* l1 where
l1.disciplina=l.disciplina and l1.docente <> l.docente and
l1.ano_lectivo <= $ano_lectivo and l1.ano_lectivo > l.ano_lectivo and
l.classe = l1.classe ) order by disciplina";
(this query comes from a PHP script so the $... are replaced on run-time
by actual values.

I've tryed to break this thing into peaces and found out that the
"offending" part is "l1.ano_lectivo > l.ano_lectivo"

BTW: to clarify this whole thing. The tables represent the way in wich
teacher (docente) teach some subjects (disciplina). Everytime there is a
change (a new teacher starts teaching that subject, or something
similar) there is a new record saying to what schhol year it refers
(ano_lectivo). If there is a record say in 1999 of a teacher teaching
some subject and there are no other records that means that if we look
at the data in 2010 it is still valid. There are different kinds of
assignment (responsible, efectively teaching, juri, etc). What the query
try's to do is given a teacher and school year (and other things) find
out wich are the subjects that he is teaching. The subselect serves to
discover if there is someone else teaching the subject after the record
that we found for thaht teacher (i think i'm starting to get confused
here :( ).

this system is a 6.4.2, it was vacuumed and it crashes, *ly...
Does anyone have a clue of why?

Thanks.

P.S. : As always I'm available to give further explanations that could
help in solving this problem.

Thanks for you attention

--
        Mario Filipe

        http://www.veryComputer.com/~mjnf

---------------------------(end of broadcast)---------------------------

 
 
 

A crashing query

Post by Tom La » Fri, 30 Mar 2001 02:21:26



Quote:> Yestrday a new class was added (this is the only difference from before,
> and since then the following query no longer works:
>  select distinct disciplina from lecciona* l where l.docente='$id' and
> l.ano_lectivo<= $ano_lectivo and l.classe in ('lecciona','responsvel')
> and not exists (select 1 from lecciona* l1 where
> l1.disciplina=l.disciplina and l1.docente <> l.docente and
> l1.ano_lectivo <= $ano_lectivo and l1.ano_lectivo > l.ano_lectivo and
> l.classe = l1.classe ) order by disciplina";

Subselects in inherited queries are a tricky area (in fact I just
yesterday fixed a bug in 7.1RC1 in that specific area).

Quote:> this system is a 6.4.2,

Try updating to something less ancient --- there are tons of bugs in
6.4.*'s subselect implementation.  I'm amazed not that this crashes,
but that it ever worked at all.  You really should be on 7.0.3, if
not experimenting with 7.1.

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command