From: | Richard Bayet <bayet(at)enseirb(dot)fr> |
---|---|
To: | Vida Luz Arista <vlal(at)ideay(dot)net(dot)ni> |
Cc: | pgsql-admin(at)postgresql(dot)org |
Subject: | Re: Query |
Date: | 2001-08-24 15:59:32 |
Message-ID: | 3B8679E4.F0FE7386@enseirb.fr |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)postgresql(dot)org)
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2001-08-24 16:09:55 | Re: Query |
Previous Message | Vida Luz Arista | 2001-08-24 14:54:24 | Query |