Re: Optimization in C

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Jerome Raupach <jraupach(at)intelcom(dot)fr>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Optimization in C
Date: 2000-08-17 15:58:11
Message-ID: Pine.BSF.4.10.10008170853030.96893-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Is the thing you're trying to do really different from
SELECT service, noeud, rubrique, sum(date) FROM table
group by service, noeud, rubrique, assuming table is the
same in both queries of course.

Also, since you aren't distincting the outside query, wouldn't
you be doing the same sequence of service, noeud and rubrique
more than once in the inner loop if it had more than one date
(if it's only got one, why bother summing?)

Stephan Szabo
sszabo(at)bigpanda(dot)com

On Thu, 17 Aug 2000, Jerome Raupach wrote:

> This solution isn't good when there are +10000 tuples in the table, it's
> slowly...
> anybody can help me ? :
>
>
> string = "SELECT service, noeud, rubrique FROM table" ;
> res = PQexec( conn, string.data() ) ;
> if ( (! res) || (status = PQresultStatus( res ) !=
> PGRES_TUPLES_OK) )
> {
> cerr << _ERROR << "Problem SELECT ! " << endl ;
> cerr << _ERROR << "Error : " << PQresStatus( status ) <<
> endl ;
> cerr << _ERROR << "Error : " << PQresultErrorMessage(
> res ) << endl ;
> PQclear( res ) ;
> }
> else
> {
> for (int m=0; m < PQntuples( res ); m++)
> {
> service = PQgetvalue( resultat1, m, 0 ) ;
> noeud = PQgetvalue( resultat1, m, 1 ) ;
> rubrique = PQgetvalue( resultat1, m, 2 ) ;
>
> commande = "SELECT SUM(date) FROM table WHERE
> service='" + service +
> "' AND noeud='" + noeud + "' AND rubrique='"+ rubrique + "'" ;
> res1 = PQexec( conn, string.data() ) ;
> if ( (! res1) || (status = PQresultStatus( res1
> ) != PGRES_TUPLES_OK)
> )
> {
> cerr << _ERROR << "Problem SUM ! " <<
> endl ;
> cerr << _ERROR << "Error : " <<
> PQresStatus( status ) << endl ;
> cerr << _ERROR << "Error : " <<
> PQresultErrorMessage( res1 ) << endl
> ;
> PQclear( res1 ) ;
> }
> else
> {
> cout << _TRACE << "SUM ok." << endl ;
> PQclear( res1 ) ;
> }
> }
> PQclear( res ) ;
> }
>
> Thanks. jerome.
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Selle 2000-08-17 18:05:17 Inserting a select statement result into another table
Previous Message Ross J. Reedstrom 2000-08-17 15:35:47 Re: Large # of Tables, Getting ready for the enterprise