Subject: | Poor performance with large amounts of placeholders. |
Date: | Fri, 26 Jun 2015 14:52:53 +1000 |
To: | bug-DBD-Pg [...] rt.cpan.org |
From: | Matt Tyson <mtyson [...] redhat.com> |
Hi,
I've found a rather extreme case where our application will generate a
query with approx 20,000 '?' placeholders.
When DBD::Pg gets such a query, it spends a large amount of time (3 - 5
seconds) processing the query before dispatching it on to postgres.
I found this was due to the way placeholders are stored in linked lists.
It essentially is a quadratic algorithm that becomes quite slow with
large lists.
I've had a stab at optimizing the code to use an array and would like
your feedback on the patch. It passes the test suite and I'm not aware
of any changed behavior with the patch applied.
There's probably some more optimizing that can be done, however this is
a first pass. The patch is against version 3.5.1
I've attached a reproducer script that generates a query with 50,000
placeholders.
Without the patch, execution time is approx 20 seconds
With the patch, execution time is approx 900 milliseconds
Regards,
Matt.
Message body is not shown because sender requested not to inline it.
Message body is not shown because sender requested not to inline it.