Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Interfaces odbc

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 06:20 AM
Jeremy Faith
 
Posts: n/a
Default SQLBulkOperations Segfault

Hi,

I have been experimenting with SQLBulkOperations to see if it is faster
at inserting rows than using individual insert statements.
But when I run the attached(bo.c) example program it segfaults(note,
this program works correctly with an Oracle ODBC connection).

The program requires the following table.
create table customer
(
cust_num integer not null,
first_name char(20),
last_name char(20)
);

Also the odb_db_open function call uses a hard coded DSN=pg_cdc_w,
username=username and password=password.

I am using the latest versions of pgsql+postgres on Linux i.e.
psqlodbc-08.03.0100
postgresql-8.3.1

I turned on the ODBC debug log and added some log output to the driver
and found that the segfault is occurring in the results.c:SC_pos_add
function.

In particular the log shows
POS ADD fi=(nil) ti=(nil)

and the segfault occurs on this line:-
if (*used != SQL_IGNORE && fi[i]->updatable)
So fi is NULL but is being referenced.

I did a bit more checking and found that parse_statement sets up
stmt->ird->irdopts.fi i.e.
if (SC_update_not_ready(stmt))
parse_statement(s.stmt, TRUE); /* not preferable */
so adding
fi=stmt->ird->irdopts.fi;
after parse_statement gets past this segfault.

But then another segfault occurs in the results.cositioned_load
function as stmt->load_stmt is NULL
so strlen(stmt->load_stmt) segfaults.

The code is complicated and I have not been able to determine how to fix
this, it seems likely to me that even the fi fix may be covering up an
earlier problem somewhere else in the code.

Does anybody use SQLBulkOperations to load data?
If so is it faster than individual inserts?

The postgres driver included with unixODBC fails as well but it at least
return a standard ODBC error so I suppose it doesn't support
SQLBulkOperations, I understand the unixODBC driver is defunct anyway.

I have noticed that the unixODBC postgres driver is significantly
quicker when using a prepared insert to insert 100,000 rows.
Specifically psqlodbc takes about 75% longer, but this is reduced to
about 45% longer when 'UseServerSidePrepare = 1' is set. Indeed it was
this speed difference that prompted me to try SQLBulkOperation in the
first place.
Are there any other setting that may improve the speed of the psqlodbc
driver?
Any ideas why the old unixODBC driver is so much faster?

Regards,
Jeremy Faith


--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-20-2008, 06:13 AM
Hiroshi Inoue
 
Posts: n/a
Default Re: SQLBulkOperations Segfault

Jeremy Faith wrote:
> Hi,
>
> I have been experimenting with SQLBulkOperations to see if it is faster
> at inserting rows than using individual insert statements.
> But when I run the attached(bo.c) example program it segfaults(note,
> this program works correctly with an Oracle ODBC connection).
>
> The program requires the following table.
> create table customer
> (
> cust_num integer not null,
> first_name char(20),
> last_name char(20)
> );
>
> Also the odb_db_open function call uses a hard coded DSN=pg_cdc_w,
> username=username and password=password.
>
> I am using the latest versions of pgsql+postgres on Linux i.e.
> psqlodbc-08.03.0100
> postgresql-8.3.1
>
> I turned on the ODBC debug log and added some log output to the driver
> and found that the segfault is occurring in the results.c:SC_pos_add
> function.
>
> In particular the log shows
> POS ADD fi=(nil) ti=(nil)
>
> and the segfault occurs on this line:-
> if (*used != SQL_IGNORE && fi[i]->updatable)
> So fi is NULL but is being referenced.
>
> I did a bit more checking and found that parse_statement sets up
> stmt->ird->irdopts.fi i.e.
> if (SC_update_not_ready(stmt))
> parse_statement(s.stmt, TRUE); /* not preferable */
> so adding
> fi=stmt->ird->irdopts.fi;
> after parse_statement gets past this segfault.
>
> But then another segfault occurs in the results.cositioned_load
> function as stmt->load_stmt is NULL
> so strlen(stmt->load_stmt) segfaults.
>
> The code is complicated and I have not been able to determine how to fix
> this, it seems likely to me that even the fi fix may be covering up an
> earlier problem somewhere else in the code.


Before calling SQLExecDirect(), please set the SQL_ATTR_CURSOR_TYPE
to SQL_CURSOR_STATIC or SQL_CURSOR_KEYSET_DRIVER and also set the
SQL_ATTR_CONCURRENCY to SQL_CONCUR_ROWVER.

regards,
Hiroshi Inoue

--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-24-2008, 06:15 PM
Jeremy Faith
 
Posts: n/a
Default Re: SQLBulkOperations Segfault

Hiroshi Inoue wrote:
> Jeremy Faith wrote:
>> Hi,
>>
>> I have been experimenting with SQLBulkOperations to see if it is
>> faster at inserting rows than using individual insert statements.
>> But when I run the attached(bo.c) example program it segfaults(note,
>> this program works correctly with an Oracle ODBC connection).
>>
>> The program requires the following table.
>> create table customer
>> (
>> cust_num integer not null,
>> first_name char(20),
>> last_name char(20)
>> );
>>
>> Also the odb_db_open function call uses a hard coded DSN=pg_cdc_w,
>> username=username and password=password.
>>
>> I am using the latest versions of pgsql+postgres on Linux i.e.
>> psqlodbc-08.03.0100
>> postgresql-8.3.1
>>
>> I turned on the ODBC debug log and added some log output to the
>> driver and found that the segfault is occurring in the
>> results.c:SC_pos_add function.
>>
>> In particular the log shows
>> POS ADD fi=(nil) ti=(nil)
>>
>> and the segfault occurs on this line:-
>> if (*used != SQL_IGNORE && fi[i]->updatable)
>> So fi is NULL but is being referenced.
>>
>> I did a bit more checking and found that parse_statement sets up
>> stmt->ird->irdopts.fi i.e.
>> if (SC_update_not_ready(stmt))
>> parse_statement(s.stmt, TRUE); /* not preferable */
>> so adding
>> fi=stmt->ird->irdopts.fi;
>> after parse_statement gets past this segfault.
>>
>> But then another segfault occurs in the results.cositioned_load
>> function as stmt->load_stmt is NULL
>> so strlen(stmt->load_stmt) segfaults.
>>
>> The code is complicated and I have not been able to determine how to
>> fix this, it seems likely to me that even the fi fix may be covering
>> up an earlier problem somewhere else in the code.

>
> Before calling SQLExecDirect(), please set the SQL_ATTR_CURSOR_TYPE
> to SQL_CURSOR_STATIC or SQL_CURSOR_KEYSET_DRIVER and also set the
> SQL_ATTR_CONCURRENCY to SQL_CONCUR_ROWVER.
>

That fixes it, thanks.

Perhaps SQLBulkOperations could check that these attributes are set
correctly and return an ODBC error if not. It is not clear from any ODBC
documentation that I have read that these need to be set this way to do
an SQL_ADD.

I have done a speed test and have found that the SQLBulkOperations
method takes about twice as long as using a prepared insert. So as it is
faster and easier the prepared insert seems to be the way to go.

Using the prepared insert method, the old driver included with unixODBC
is considerably faster than psqlodbcw, any idea why?
Is there any problem with using the old driver?

Regards,
Jeremy Faith

--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:30 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145