jplindstrom / p5-dbix-class-batchupdate Goto Github PK
View Code? Open in Web Editor NEWPerl module to update batches of DBIC rows with as few queries as possible
Perl module to update batches of DBIC rows with as few queries as possible
Sorry that I didn't notice this the first time around. This is not... ideal. What you want to do is to fall back to the original one-by-one update() logic when any part of the PK (which could be multicolumn) is dirty. Perhaps with a warning (yada-yada BatchUpdate ineffective).
Doing anything else is likely to result in bugs that will be extraordinarily hard to diagnose.
Hi Johan,
just testet the module and failed when trying to update a single attribute for 10.000 rows with a single batch_update() - call. The underlying database is an Oracle Enterprise DB v11. Getting a
Seems as the update is made with an IN list containing the primary keys. IN lists are limited to 1000 elements for Oracle databases.
Here's the stack
DBIx::Class::Schema::throw_exception(ADD::Schema=HASH(0x563ef5a33988), "DBI Exception: DBD::Oracle::st execute failed: ORA-01795: max"...) called at /home/damenc/workspace/add.dev/lib/site_perl/DBIx/Class/Storage.pm line 113
DBIx::Class::Storage::throw_exception(DBIx::Class::Storage::DBI::Oracle::Generic=HASH(0x563ef5a44880), "DBI Exception: DBD::Oracle::st execute failed: ORA-01795: max"...) called at /home/damenc/workspace/add.dev/lib/site_perl/DBIx/Class/Storage/DBI.pm line 1501
DBIx::Class::Storage::DBI::__ANON__[/home/damenc/workspace/add.dev/lib/site_perl/DBIx/Class/Storage/DBI.pm:1508]("DBD::Oracle::st execute failed: ORA-01795: maximum number of "..., DBI::st=HASH(0x563ef7390068), undef) called at /home/damenc/workspace/add.dev/lib/site_perl/DBIx/Class/Storage/DBI.pm line 1836
DBIx::Class::Storage::DBI::_dbh_execute(DBIx::Class::Storage::DBI::Oracle::Generic=HASH(0x563ef5a44880), DBI::db=HASH(0x563ef5eb4268), "UPDATE auftrag SET abruf_tag = ? WHERE ( id_auftrag IN ( ?, ?"..., ARRAY(0x563ef6f158a8), ARRAY(0x563ef66562b8)) called at /home/damenc/workspace/add.dev/lib/site_perl/DBIx/Class/Storage/DBI/Oracle/Generic.pm line 297
DBIx::Class::Storage::DBI::Oracle::Generic::_dbh_execute(DBIx::Class::Storage::DBI::Oracle::Generic=HASH(0x563ef5a44880), DBI::db=HASH(0x563ef5eb4268), "UPDATE auftrag SET abruf_tag = ? WHERE ( id_auftrag IN ( ?, ?"..., ARRAY(0x563ef6f158a8), ARRAY(0x563ef66562b8)) called at /home/damenc/workspace/add.dev/lib/site_perl/DBIx/Class/Storage/DBI.pm line 840
DBIx::Class::Storage::DBI::dbh_do(DBIx::Class::Storage::DBI::Oracle::Generic=HASH(0x563ef5a44880), "_dbh_execute", "UPDATE auftrag SET abruf_tag = ? WHERE ( id_auftrag IN ( ?, ?"..., ARRAY(0x563ef6f158a8), ARRAY(0x563ef66562b8)) called at /home/damenc/workspace/add.dev/lib/site_perl/DBIx/Class/Storage/DBI.pm line 1817
DBIx::Class::Storage::DBI::_execute(DBIx::Class::Storage::DBI::Oracle::Generic=HASH(0x563ef5a44880), "update", DBIx::Class::ResultSource::Table=HASH(0x563ef5a89848), HASH(0x563ef6dbfe10), REF(0x563ef6fd4838)) called at /home/damenc/workspace/add.dev/lib/site_perl/DBIx/Class/Storage/DBI.pm line 2398
DBIx::Class::Storage::DBI::update(DBIx::Class::Storage::DBI::Oracle::Generic=HASH(0x563ef5a44880), DBIx::Class::ResultSource::Table=HASH(0x563ef5a89848), HASH(0x563ef6dbfe10), REF(0x563ef6fd4838)) called at /home/damenc/workspace/add.dev/lib/site_perl/DBIx/Class/ResultSet.pm line 2013
DBIx::Class::ResultSet::_rs_update_delete(ADD::Schema::ResultSet::Auftrag=HASH(0x563ef6f07ee0), "update", HASH(0x563ef6dbfe10)) called at /home/damenc/workspace/add.dev/lib/site_perl/DBIx/Class/ResultSet.pm line 2062
DBIx::Class::ResultSet::update(ADD::Schema::ResultSet::Auftrag=HASH(0x563ef6f07ee0), HASH(0x563ef6dbfe10)) called at /home/damenc/workspace/add.dev/lib/site_perl/DBIx/Class/BatchUpdate/Batch.pm line 16
DBIx::Class::BatchUpdate::Batch::update(DBIx::Class::BatchUpdate::Batch=HASH(0x563ef6e4b178)) called at /home/damenc/workspace/add.dev/lib/site_perl/DBIx/Class/BatchUpdate/Update.pm line 92
DBIx::Class::BatchUpdate::Update::update(DBIx::Class::BatchUpdate::Update=HASH(0x563ef6dbfb40)) called at /home/damenc/workspace/add.dev/test.pl line 24
Hoped that module would handle exactly that as currently I'm solving this by updating rows in sliced portions via primary key.
This is a really fragile way of approaching this. Imagine someone writing an unpacked version of everything on CPAN to a database and comes across the source of your module. OOOOOPS.
Instead use a proper serializer which will account for undefs, and any other weird shit out there (however do not use the module I linked - it's internal with no API guarantees)
Test suite fails with perl 5.23.x:
Experimental push on scalar is now forbidden at t/dbix-class-batchupdate-update.t line 44, near "$args)"
Execution of t/dbix-class-batchupdate-update.t aborted due to compilation errors.
t/dbix-class-batchupdate-update.t ..
Dubious, test returned 255 (wstat 65280, 0xff00)
No subtests run
The Batch->update method assumes the PK column is called "id".
Hi @jplindstrom ,
Thanks for your efforts in writing this module for batch update.
I would like to use this module for batch updating via DBIx-Class in my project. But it seems at present its accepting only id as primary key column name as documented.
Usually we can have primary key column name different from id, i prepared patch to use non-id as primary key column name.
I verified tests and non-id field test scenario 'pkid' is already covered in your test script and its passed with this patch.
Could you please review this git patch(i zipped git patch file as github not allowing me to attach .patch files) and merge to main repo if possible.
Thanks
Mohan
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.