500 times slower - Mailing list pgsql-odbc

From Karol Szkudlarek
Subject 500 times slower
Date
Msg-id 4202379B.5020604@mikronika.com.pl
Whole thread Raw
Responses Re: 500 times slower  (Karol Szkudlarek <karol@mikronika.com.pl>)
List pgsql-odbc
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
#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();
}

pgsql-odbc by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: odbc.sql?
Next
From: "Brien R. Givens"
Date:
Subject: Re: Welcome to the pgsql-odbc list!