Generar funcion en C++ para PostgreSql

From: Carlos GR <intuitpg(at)yahoo(dot)com(dot)ar>
To: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Generar funcion en C++ para PostgreSql
Date: 2006-11-25 14:33:43
Message-ID: 20061125143343.85950.qmail@web36104.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Un saludo a todos los miembros de la lista.
Por medio de la presente les quiero plantear un problema que se me ha presentado al compilar por vez PRIMERA una funcion en C++ para PostgreSQL, esperando me puedan ayudar al respecto.
Pues he tratado de compilar una funcion para utilizarla en PostgreSql que pueda utilizar para observar el rendimiento de una consulta, esta funcion muestra datos como : cuantas filas ha leido el comando, cuanto bloques de datos a utilizado (los bloques son de 8K), cuanto de estos bloques se encontraron en la memoria cache o no, para los datos leidos y los indices. Recuperando para ello informacion de las tablas pg_stat_all_tables, y pg_statio_all_tables. (Para los interesado es funcion lo halle en el libro PostgreSql de Korry y Sunsan Douglas).
La funcion consta del archivo "timer.cc", el codigo fuente y un archivo "makefile" que usa para la compilación. Estos dos archivos se detallan para mas comodidad al final del correo echenle una ojeada.
Bueno el problema es que la fucion no compila y me genera bastantes errores.(ya se que algunos me pueden decir que mas que de PostGress es una consulta para un lista C++, pero no es tan asi ya que sirve para adicionar funcionalidades a PostGreSql).
Al ejecutar make me sale los siguientes mensajes de error
C:\ARCHIV~1\POSTGR~1\8.1>make
gpp -g -Wall -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Winline -Wdeclar
on-after-statement -Wendif-labels -fno-strict-aliasing timer.cc -lpgport
ntl -lssleay32 -leay32 -lcomerr32 -lkrb5_32 -lz -lwsock32 -lm -lws2_32 -lshf
er -o timer
cc1plus.exe: warning: command line option "-Wmissing-prototypes" is valid for
a/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wdeclaration-after-statement" is
id for C/ObjC but not for C++
timer.cc:7:21: error: pqxx/pqxx: No such file or directory (ENOENT)
timer.cc:10: error: expected namespace-name before ';' token
timer.cc:10: error: '<type error>' is not a namespace
timer.cc:11: error: expected namespace-name before ';' token
timer.cc:11: error: '<type error>' is not a namespace
timer.cc:13: error: 'string' does not name a type
timer.cc:19: error: 'string' does not name a type
timer.cc:25: error: 'result' does not name a type
timer.cc:35: error: 'result' does not name a type
timer.cc:44: error: 'result' has not been declared
timer.cc:44: error: expected ',' or '...' before '&' token
timer.cc:44: error: ISO C++ forbids declaration of 'tuple' with no type
timer.cc: In function 'int getDelta(int)':
timer.cc:49: error: 'end' was not declared in this scope
timer.cc:49: error: 'column' was not declared in this scope
timer.cc:50: error: 'beg' was not declared in this scope
timer.cc: At global scope:
timer.cc:56: error: expected ',' or '...' before '&' token
timer.cc:56: error: ISO C++ forbids declaration of 'result' with no type
timer.cc: In function 'unsigned int getColumnWidth(int)':
timer.cc:60: error: request for member 'size' in 'result', which is of non-cl
type 'const int'
timer.cc:61: error: invalid types 'const int[int]' for array subscript
timer.cc:61: error: 'column' was not declared in this scope
timer.cc:62: error: invalid types 'const int[int]' for array subscript
timer.cc: At global scope:
timer.cc:68: error: 'string' does not name a type
timer.cc:73: error: expected ',' or '...' before '&' token
timer.cc:73: error: ISO C++ forbids declaration of 'result' with no type
timer.cc: In function 'void printDeltas(int)':
timer.cc:79: error: 'cout' was not declared in this scope
timer.cc:79: error: 'fill' was not declared in this scope
timer.cc:79: error: 'endl' was not declared in this scope
timer.cc:94: error: 'begTuples' was not declared in this scope
timer.cc:96: error: 'endTuples' was not declared in this scope
timer.cc:98: error: 'begBlocks' was not declared in this scope
timer.cc:98: error: 'endBlocks' was not declared in this scope
timer.cc:109: error: 'setw' was not declared in this scope
timer.cc:109: error: 'left' was not declared in this scope
timer.cc:109: error: 'right' was not declared in this scope
timer.cc:139: error: 'setw' was not declared in this scope
timer.cc:139: error: 'left' was not declared in this scope
timer.cc:139: error: 'right' was not declared in this scope
timer.cc: In function 'int main(int, char**)':
timer.cc:157: error: 'connection' was not declared in this scope
timer.cc:157: error: expected `;' before 'conn'
timer.cc:159: error: 'work' was not declared in this scope
timer.cc:159: error: expected `;' before 'tran1'
timer.cc:161: error: expected initializer before '&' token
timer.cc:162: error: expected initializer before '&' token
timer.cc:164: error: expected initializer before '&' token
timer.cc:166: error: 'tran1' was not declared in this scope
timer.cc:170: error: expected `;' before 'tran2'
timer.cc:172: error: expected initializer before '&' token
timer.cc:173: error: expected initializer before '&' token
timer.cc:175: error: 'begTupleValues' was not declared in this scope
timer.cc:175: error: 'endTupleValues' was not declared in this scope
timer.cc:175: error: 'begBlockValues' was not declared in this scope
timer.cc:175: error: 'endBlockValues' was not declared in this scope
timer.cc: At global scope:
timer.cc:56: warning: 'unsigned int getColumnWidth(int)' defined but not used
make.exe: *** [timer] Error 1
Permítanme aclarar la función se ha hecho para la versión 7.3x y aunque lo estoy compilando para la version 8.1.5 de produccion de PG, no creo que eso sea el problema. Ademas el Sistema operativo en el que lo compilo es Windows 2003 y el compilador que uso es el GCC de GNU 4.0.1 que viene con el paquete de compilacion DJGPP para DOS
Uno de los problemas es no encuentra el archivo de cabecera pqxx/pqxx lo he buscado pero no se donde esta.
Gracias de antemano, espero me puedan ayudar.
#
# Archivo MakeFile Real
#
# NOTA: modifique la ruta de PXX-CONFIG para adecuarla
# a su configuración
#
# yo he MODIFICADO la ruta de PXX-CONFIG por "bin/pg_config.exe"
# para adecuarla a la plataforma de Windows
#
PQXX-CONFIG = /usr/local/pg803/bin/pqxx-config
CXXFLAGS = -g -Wall $(shell $(PQXX-CONFIG) --cflags)
LDLIBS = $(shell $(PQXX-CONFIG) --libs)
##############################################################################
## end
##############################################################################
EXES = timer
all: $(EXES)
clean:
rm -f $(EXES)
Abajo comienza el codigo fuente de la funcion
//***************************************
//* Archivo timer.cc *
//* con el codigo fuente *
//***************************************
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <functional>
#include <pqxx/pqxx>
#include <unistd.h> // For sleep()
using namespace PGSTD;
using namespace pqxx;
const string tupleQuery( "SELECT"
" relname, seq_scan, seq_tup_read, idx_scan, idx_tup_fetch"
" FROM"
" pg_stat_all_tables" );
const string blockQuery( "SELECT"
" relname, heap_blks_read, heap_blks_hit, idx_blks_read, idx_blks_hit"
" FROM"
" pg_statio_all_tables" );
static const result getTupleValues( work & tran, const char * tableName )
{
if( tableName == 0 )
return( tran.exec( tupleQuery + " ORDER by relname" ));
else
return( tran.exec( tupleQuery + " WHERE relname = '" + tableName + "'" ));
}
static const result getBlockValues( work & tran, const char * tableName )
{
if( tableName == 0 )
return( tran.exec( blockQuery + string( " ORDER by relname" )));
else
return( tran.exec( blockQuery + " WHERE relname = '" + tableName + "'" ));
}
static int getDelta( const result::tuple & beg, const result::tuple & end, const char * column )
{
int endVal = 0;
int begVal = 0;
end[column].to( endVal );
beg[column].to( begVal );
return( endVal - begVal );
}
static unsigned int getColumnWidth( const result & result, const string & column )
{
unsigned int max = 0;
for( int row = 0; row < result.size(); ++row )
if( result[row][column].size() > max )
max = result[row][column].size();
return( max );
}
static string fill( unsigned int len, char c )
{
return( string( len, c ));
}
static void printDeltas( const result & begTuples, const result & endTuples, const result & begBlocks, const result & endBlocks )
{
// unsigned int tableNameWidth = getColumnWidth( begTuples, "relname" );
unsigned int nameWidth = 15;

cout << '+' << fill( nameWidth, '-' ) << "+-----------------------------------+----------------------------------+" << endl;
cout << '|' << fill( nameWidth, ' ' ) << "| SEQUENTIAL I/O | INDEXED I/O |" << endl;
cout << '|' << fill( nameWidth, ' ' ) << "| scans | tuples | heap_blks |cached| scans | tuples | idx_blks |cached|" << endl;
cout << '|' << fill( nameWidth, '-' ) << "+-------+--------+-----------+------+-------+--------+----------+------+" << endl;
int totSeqScans = 0;
int totSeqTuples = 0;
int totHeapBlks = 0;
int totHeapHits = 0;
int totIdxScans = 0;
int totIdxTuples = 0;
int totIdxBlks = 0;
int totIdxHits = 0;
int tableCount = 0;
for( int row = 0; row < begTuples.size(); ++row )
{
int seqScans = getDelta( begTuples[row], endTuples[row], "seq_scan" );
int seqTuples = getDelta( begTuples[row], endTuples[row], "seq_tup_read" );
int heapBlks = getDelta( begBlocks[row], endBlocks[row], "heap_blks_read" );
int heapHits = getDelta( begBlocks[row], endBlocks[row], "heap_blks_hit" );
int idxScans = getDelta( begTuples[row], endTuples[row], "idx_scan" );
int idxTuples = getDelta( begTuples[row], endTuples[row], "idx_tup_fetch" );
int idxBlks = getDelta( begBlocks[row], endBlocks[row], "idx_blks_read" );
int idxHits = getDelta( begBlocks[row], endBlocks[row], "idx_blks_hit" );
if(( seqScans + seqTuples + heapBlks + heapHits + idxScans + idxTuples + idxBlks + idxHits ) > 0 )
{
cout << '|' << setw( nameWidth ) << left << begTuples[row]["relname"].c_str() << right ;
cout << '|' << setw( 6 ) << seqScans << ' ';
cout << '|' << setw( 7 ) << seqTuples << ' ';
cout << '|' << setw( 10 ) << heapBlks << ' ';
cout << '|' << setw( 5 ) << heapHits << ' ';

cout << '|' << setw( 6 ) << idxScans << ' ';
cout << '|' << setw( 7 ) << idxTuples << ' ';
cout << '|' << setw( 9 ) << idxBlks << ' ';
cout << '|' << setw( 5 ) << idxHits << ' ';
cout << '|' << endl;

tableCount += 1;
totSeqScans += seqScans;
totSeqTuples += seqTuples;
totHeapBlks += heapBlks;
totHeapHits += heapHits;
totIdxScans += idxScans;
totIdxTuples += idxTuples;
totIdxBlks += idxBlks;
totIdxHits += idxHits;

}
}
cout << '+' << fill( nameWidth, '-' ) << "+-------+--------+-----------+------+-------+--------+----------+------+" << endl;
if( tableCount > 1 )
{
cout << '|' << setw( nameWidth ) << left << "Totals" << right ;
cout << '|' << setw( 6 ) << totSeqScans << ' ';
cout << '|' << setw( 7 ) << totSeqTuples << ' ';
cout << '|' << setw( 10 ) << totHeapBlks << ' ';
cout << '|' << setw( 5 ) << totHeapHits << ' ';

cout << '|' << setw( 6 ) << totIdxScans << ' ';
cout << '|' << setw( 7 ) << totIdxTuples << ' ';
cout << '|' << setw( 9 ) << totIdxBlks << ' ';
cout << '|' << setw( 5 ) << totIdxHits << ' ';
cout << '|' << endl;
cout << '+' << fill( nameWidth, '-' ) << "+-------+--------+-----------+------+-------+--------+----------+------+" << endl;
}
}
int main( int argc, char * argv[] )
{
connection conn;
work tran1( conn, "getBegValues" );
const result & begTupleValues = getTupleValues( tran1, argc > 2 ? argv[2] : 0 );
const result & begBlockValues = getBlockValues( tran1, argc > 2 ? argv[2] : 0 );
const result & ignore = tran1.exec( argv[1] );
tran1.commit();
sleep( 1 );
work tran2( conn, "getEndValues" );
const result & endTupleValues = getTupleValues( tran2, argc > 2 ? argv[2] : 0 );
const result & endBlockValues = getBlockValues( tran2, argc > 2 ? argv[2] : 0 );
printDeltas( begTupleValues, endTupleValues, begBlockValues, endBlockValues );

}
/*
$ timer ¡ÈSELECT * FROM recalls;¡É
+-----------------------------------+----------------------------------+
| SEQUENTIAL I/O | INDEXED I/O |
| scans | tuples | heap_blks |cached| scans | tuples | idx_blks |cached|
+-------+--------+-----------+------+-------+--------+----------+------+
| 1 | 39241 | 4412 | 0 | 0 | 0 | 0 | 0 |
+-------+--------+-----------+------+-------+--------+----------+------+
*/

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2006-11-25 16:45:57 Re: Generar funcion en C++ para PostgreSql
Previous Message Juan Martínez 2006-11-25 10:44:31 Re: Como eliminar los espacios dentro de un SELECT cuando se usa COALESCE..