Re: Pb d'ouverture de curseur

From: Valérie SCHNEIDER <valerie(dot)schneider(at)meteo(dot)fr>
To: Jean-Paul ARGUDO <jean-paul(at)argudo(dot)org>, pgsql-fr-generale <pgsql-fr-generale(at)postgresql(dot)org>
Subject: Re: Pb d'ouverture de curseur
Date: 2004-09-30 07:44:05
Message-ID: 1096530245.13051.14.camel@nazar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-fr-generale

Bonjour,

>
> > J'ai un pb [...]
> >
> > [valerie(at)nazar valerie]$ ecpg --version
> > ecpg (PostgreSQL 8.0.0beta1) 3.2.0
>
> Déjà, peux tu essayer avec la béta 3?! Si j'ai bien compté (dans le fichier
> "changes since beta1"), il y a une petite dizaine de bugs corrigés, rien que sur
> ECPG (momjian et meskes).
>
> > select u.ID_STATION,u.DAT,u.DAT_CALC,u.DAT_STAMP,u.ORIGINE
> > ,null,null,null ,cast(to_char(dat,'J') as integer) ,u.HRR from H u
> > where (u.DAT BETWEEN
> > to_timestamp('10000101000000','YYYYMMDDHH24MISS')::timestamp AND
> > to_timestamp('30000101000000','YYYYMMDDHH24MISS')::timestamp) AND
> > (u.id_station between '31069001' AND '31069001' ) order by DAT
>
> Cela fait longtemps que je n'ai pas pratiqué ECPG (ni Pro*C d'ailleurs), mais
> comme tu n'as pas de réponse, j'en tente une... Sait on jamais!
>
> Ta requête me semble pour le moins curieuse:

Oui, mais elle est constituée dynamiquement, il peut y avoir plusieurs
tables (c'est pourquoi il y a renommage), plusieurs conditions (d'où
un between qui pourrait ne pas apparaître), etc.
>
> a) ton to_timestamp n'est il pas redondant avec le cast ::timestamp?

Le to_timestamp me semble nécessaire pour transformer la chaine de
caractère en type timestamp; le "::timestamp" est la solution que
j'avais trouvé pour forcer l'optimiseur à utiliser un index :

clisys=> explain select
u.ID_STATION,u.DAT,u.DAT_CALC,u.DAT_STAMP,u.ORIGINE ,null,null,null
,cast(to_char(dat,'J') as integer) ,u.HRR from H u where (u.DAT
BETWEEN to_timestamp('10000101000000','YYYYMMDDHH24MISS') AND
to_timestamp('30000101000000','YYYYMMDDHH24MISS')) AND (u.id_station
between '31069001' AND '31069001' ) order by DAT;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=776067.77..776069.21 rows=2862 width=53)
Sort Key: dat
-> Seq Scan on h u (cost=0.00..776034.91 rows=2862 width=53)
Filter: (((dat)::timestamp with time zone >=
to_timestamp('10000101000000'::text, 'YYYYMMDDHH24MISS'::text)) AND
((dat)::timestamp with time zone <= to_timestamp('30000101000000'::text,
'YYYYMMDDHH24MISS'::text)) AND ((id_station)::text >= '31069001'::text)
AND ((id_station)::text <= '31069001'::text))
(4 lignes)

clisys=> explain select
u.ID_STATION,u.DAT,u.DAT_CALC,u.DAT_STAMP,u.ORIGINE ,null,null,null
,cast(to_char(dat,'J') as integer) ,u.HRR from H u where (u.DAT
BETWEEN to_timestamp('10000101000000','YYYYMMDDHH24MISS')::timestamp AND
to_timestamp('30000101000000','YYYYMMDDHH24MISS')::timestamp) AND
(u.id_station between '31069001' AND '31069001' ) order by DAT;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=5486.68..5488.11 rows=2862 width=53)
Sort Key: dat
-> Index Scan using h_pk on h u (cost=0.00..5453.82 rows=2862
width=53)
Index Cond: (((id_station)::text >= '31069001'::text) AND
((id_station)::text <= '31069001'::text) AND (dat >=
(to_timestamp('10000101000000'::text,
'YYYYMMDDHH24MISS'::text))::timestamp without time zone) AND (dat <=
(to_timestamp('30000101000000'::text,
'YYYYMMDDHH24MISS'::text))::timestamp without time zone))
(4 lignes)

>
> b) pourquoi dépareiller un peu plus haut en utilisant cast(char) ? :)
>
> c) juste un truc esthétique, renommer la table H en u alors que c'est la
> seule table de la requête? :-)
>
> d) perso, j'éviterai les cast via :: dans ecpg.. je ne sais pas trop
> pourquoi, mais je ne le sens pas trop :)

Mais je peux effectivement supprimer les "::" avec "cast ... as ...".

En attendant je tente la beta3.

>
> A+
>
> PS: oui, presque que du subjectif dans tout ça! :-)
--

********************************************************************
* Valerie SCHNEIDER Tel : +33 (0)5 61 07 81 91 *
* METEO-FRANCE Fax : +33 (0)5 61 07 81 09 *
* DSI/DEV - Bases de donnees *
* 42, avenue G. Coriolis Email : Valerie(dot)Schneider(at)meteo(dot)fr *
* 31057 TOULOUSE Cedex - FRANCE http://www.meteo.fr *
********************************************************************
* L'information contenu dans ce mail n'a aucun caractere officiel *
********************************************************************

In response to

Browse pgsql-fr-generale by date

  From Date Subject
Next Message Valérie SCHNEIDER 2004-09-30 07:46:21 Re: Pb d'ouverture de curseur
Previous Message Daniel Verite 2004-09-29 15:52:05 Re: Pb d'ouverture de curseur