Re: Query - Mailing list pgsql-admin

From Richard Bayet
Subject Re: Query
Date
Msg-id 3B8679E4.F0FE7386@enseirb.fr
Whole thread Raw
In response to Query  (Vida Luz Arista <vlal@ideay.net.ni>)
List pgsql-admin
Vida Luz Arista a écrit :

> Hi All, I have two questions
>
> 1- I have a query but this is very slow, I need to acelerate the
> consult, this result sill be show in the web.
>
> My query is:
>
> select user, descripcion from client where login not in (select
> distinct(usr_cliente) from conexion where fecha between '$date_begin' and
> '$date_end') order by user"
>
> How can I to acelerate this consult?
>
> 2- I made this function:
>
> CREATE FUNCTION list(date,date) RETURNS user
>      AS 'select distinct(usr_cliente) from conexion where fecha between
>         $date_begin and $date_end' LANGUAGE 'sql';
>
> When I execute a query to this function like:
> select select list('08-10-2001', '08-13-2001') as user;
>
> the result is just 1 row, however If I to execute the query this return
> 300 rows, why the function only return one row?
>

The query's returning the exact opposite of your function, so if you have
301 rows in your table and the function returns you 1, the query'll get 300
:)
select user, descripcion from client where login not in (select
distinct(usr_cliente) from conexion where fecha between '$date_begin' and
'$date_end') order by user"
is equivalent to:
select user, descripcion from client where login not in (select
list('$date_begin', '$date_end'))

PS: a misused "not in" clause can result in very poor performances (it
depends actually of your table contents) : if "everything that is not ..."
is huge, it's quicker to get "everything that is ..." :)

>
> Thanks in advanced,
>
> Regards,
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)


pgsql-admin by date:

Previous
From: Vida Luz Arista
Date:
Subject: Query
Next
From: Stephan Szabo
Date:
Subject: Re: Query