A crashing query

From: Mario Jorge Nunes Filipe <mjnf(at)uevora(dot)pt>
To: pgsql-admin(at)postgresql(dot)org
Subject: A crashing query
Date: 2001-03-28 11:41:12
Message-ID: 985779672.15767.4.camel@neptuno
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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','responsável')
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, violently...
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
mjnf(at)uevora(dot)pt
http://neptuno.sc.uevora.pt/~mjnf

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Mahesh Guleria 2001-03-28 11:54:52 Query
Previous Message Ascent Avenues 2001-03-28 11:29:57 postgres