From: Karol Szkudlarek <karol@mikronika.com.pl>
To: pgsql-odbc@postgresql.org
Subject: 500 times slower
Date: Thu, 03 Feb 2005 15:39:23 +0100
Message-ID: <4202379B.5020604@mikronika.com.pl> (raw)
Hi!
I have the program which using LOBS with postgresql. When I connect to
local windows server or remote linux server everything is fine. But when
I connect to remote Windows server the function SQLDirectExec runs 500
times longer than normally. Problem concerns postgres on Windows with
version > 7.4.1 and also 8.0. 7.x runs under cygwin and 8.x natively.
Previously in the old cygwin which contains 7.4.1 postgres the
performance was ok.
I've included simple test case which shows the problem.
Karol
Attachments:main2.cpp (text/plain, 3.2K) download
#include <iostream>
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
void ODBCError(SQLRETURN rc,const char*where,bool ignoreError=false)
{
bool terminate=true;
const char*err;
switch (rc)
{
case SQL_SUCCESS: err="SQL_SUCCESS" ;terminate=false;break;
case SQL_SUCCESS_WITH_INFO:err="SQL_SUCCESS_WITH_INFO";terminate=false;break;
case SQL_NO_DATA :err="SQL_NO_DATA" ;terminate=false;break;
default:
err="ERROR";break;
}
if(!ignoreError)
if (terminate)
{
std::cerr<<where<<":"<<err<<std::endl;
exit(0);
}
}
bool ODBCExec(SQLHDBC hdbc,const char* stmt)
{
SQLHSTMT hstmt;
ODBCError(SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt),"SQLAllocHandle-Stmt");
ODBCError(SQLExecDirect(hstmt,(SQLCHAR*)stmt,SQL_NTS),"SQLExecDirect",true);
ODBCError(SQLFreeHandle(SQL_HANDLE_STMT,hstmt),"SQLFreeHandle-Stmt");
return true;
}
bool ODBCTest()
{
SQLHENV henv;
ODBCError(SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv),"SQLAllocHandle-Env");
ODBCError(SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC3 ,NULL),"SQLSetEnvAttr");
SQLHDBC hdbc;
ODBCError(SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc),"SQLAllocHandle-Conn");
const char*server="pi";
const char*user="legnica_e";
const char*passwd="syndis";
ODBCError(SQLConnect(hdbc,(SQLCHAR*)server,strlen(server),(SQLCHAR*)user,strlen(user),(SQLCHAR*)passwd,strlen(passwd)),"SQLConnect");
ODBCExec(hdbc,"drop table test");
ODBCExec(hdbc,"create table test(t text)");
ODBCExec(hdbc,"create table test(t text)");
ODBCExec(hdbc,"insert into test values ('0123456789')");
for (int x=0;x<20;++x)ODBCExec(hdbc,"update test set t=t||t");
SQLHSTMT hstmt;
ODBCError(SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt),"SQLAllocHandle-Stmt");
const char*stmt="select t from test";
ULONGLONG t1,t2;
GetSystemTimeAsFileTime((FILETIME*)&t1);
ODBCError(SQLExecDirect(hstmt,(SQLCHAR*)stmt,SQL_NTS),"SQLExecDirect");
GetSystemTimeAsFileTime((FILETIME*)&t2);
t2-=t1;
std::cerr<<"SQLExecDirect time:"<<t2/10000<<"msec."<<std::endl;
SQLRETURN rc,rc2;
int maxsize=32760;
char*buf=new char[maxsize];
SQLLEN ind;
while ((rc=SQLFetch(hstmt))!=SQL_NO_DATA)
{
ODBCError(rc,"SQLFetch");
int count=0;
while((rc2=SQLGetData(hstmt,1,SQL_C_CHAR,buf,maxsize,&ind))!=SQL_NO_DATA)
{
ODBCError(rc2,"SQLGetData");
if ((ind>maxsize)||(ind==SQL_NO_TOTAL))
ind=maxsize;
count+=ind;
std::cerr<<'.';//<<"reading "<<ind<<" bytes of data"<<std::endl;
}
std::cerr<<std::endl;
ODBCError(rc2,"SQLGetData");
std::cerr<<"total "<<count<<" bytes of data"<<std::endl;
}
ODBCError(rc,"SQLFetch");
delete[] buf;
ODBCError(SQLFreeHandle(SQL_HANDLE_STMT,hstmt),"SQLFreeHandle-Stmt");
ODBCError(SQLDisconnect(hdbc),"SQLDisconnect");
ODBCError(SQLFreeHandle(SQL_HANDLE_DBC,hdbc),"SQLFreeHandle-Conn");
ODBCError(SQLFreeHandle(SQL_HANDLE_ENV,henv),"SQLFreeHandle-Env");
return 0;
}
int main(int argc,char**argv)
{
return ODBCTest();
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: karol@mikronika.com.pl
Subject: Re: 500 times slower
In-Reply-To: <4202379B.5020604@mikronika.com.pl>
References: <4202379B.5020604@mikronika.com.pl>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox