Re: SQL-Statement - Mailing list pgsql-admin

From banghe
Subject Re: SQL-Statement
Date
Msg-id 3FB3C9ED.5000603@baileylink.net
Whole thread Raw
In response to SQL-Statement  (Markus Espenhain <espenhain@etes.de>)
List pgsql-admin
Hi,

Your query should be written in much simple way:

SELECT Monatsbeitrag.lfdid, Daten.Kundennummer FROM Daten, Monatsbeitrag
WHERE
   (Daten.Vetrag widerufen = 2) AND
    Daten.ewmanfrdat IS NOTNULL AND
   (Monatsbeitrag.ID = Daten.Kundennummer ) AND
   ((Monatsbeitrag.Monat + 14 ) =  '2003-10-27 00:00:00'::timestamp ) AND
   (Monatsbeitrag.Bezahlt = 2 )
ORDER BY Daten.Name;

Your 2nd query has
Daten.ewmanfrdat IS NULL

So the result should is different and the cost for query will be
different too.

Bangh

Markus Espenhain wrote:

>Hello,
>
>sorry for my previos mail.
>This was a mistake...
>
>I have an problem with the following statement.
>This one works fine and give me the results in just a few seconds.
>
>SELECT Monatsbeitrag.lfdid, Daten.Kundennummer FROM Daten, Monatsbeitrag WHERE ((((Daten.Vetrag widerufen = 2 ) AND
NOT((Daten.ewmanfrdatIS NULL ) ) ) AND (Monatsbeitrag.ID = Daten.Kundennummer ) ) AND (((Monatsbeitrag.Monat + 14 ) =
'2003-10-2700:00:00'::timestamp ) AND (Monatsbeitrag.Bezahlt = 2 ) ) ) ORDER BY Daten.Name; 
>
>
>When I edit the statement and delete the "NOT" before "Daten.ewmanfrdat IS NULL" the Query works over 15 Minutes.
>
>SELECT Monatsbeitrag.lfdid, Daten.Kundennummer FROM Daten, Monatsbeitrag WHERE ((((Daten.Vetrag widerufen = 2 ) AND
((Daten.ewmanfrdatIS NULL ) ) ) AND (Monatsbeitrag.ID = Daten.Kundennummer ) 
>) AND (((Monatsbeitrag.Monat + 14 ) =  '2003-10-27 00:00:00'::timestamp ) AND (Monatsbeitrag.Bezahlt = 2 ) ) ) ORDER
BYDaten.Name; 
>
>OK, to select a lot of records it works a time, but for only 350 records?
>
>Where is my problem?
>
>Can anybody help me please.
>
>Regards
>
>Markus
>
>
>


pgsql-admin by date:

Previous
From: Markus Espenhain
Date:
Subject: SQL-Statement
Next
From: "scott.marlowe"
Date:
Subject: Re: easy way to copy all DBs and users on a server