Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Offsite payment methods such as Amazon Pay and PayPal load payment transactions based on a remote_id field:
$transactions = commerce_payment_transaction_load_multiple(array(), array('remote_id' => $txn_id));
This results in a JOIN along this field, which in some cases can prove to be extremely problematic as the remote_id field is a varchar (text string).
Proposed resolution
Add an index to both remote_id fields in the entity property tables.
Remaining tasks
Requires an update hook and change to schema.
User interface changes
None
API changes
None
Data model changes
Add `remote_id` as an index on {commerce_payment_transaction} and {commerce_payment_transaction_revision}. Not sure if adding as a `foreign key` would also help, but might not hurt.
Comment | File | Size | Author |
---|---|---|---|
#11 | 2924395-remote_id-index_exists.patch | 1.03 KB | torgosPizza |
|
Comments
Comment #2
torgosPizzaI'm not sure if it was just a concurrent request with something else that caused a lock, but this select query revealed this index issue for us. It took 160 seconds to complete, and was the result of someone coming to a PayPal return URL.
Patch attached.
Comment #3
torgosPizzaTypo
Comment #4
rszrama CreditAttribution: rszrama at Centarro commentedGreat find, Erik. Do you think we'll need a warning on this to update via drush for large payment transaction tables similar to 1.14's order update? Or perhaps a disk space warning - that new index eat up a lot of space for you?
Comment #5
torgosPizzaThat might not be a bad idea. At least a "Use Drush" warning, because the update did take several minutes to complete for us, with 1.5 million rows of transactions.
I don't see the indexes taking up too much space, considering the amount of data, but it's hard to tell as our hosting provider (Acquia) doesn't give us permission to read from our InnoDB stats database. But here's what I get from getting the table status:
Hope that helps! I'll let you know if I see any changes in behavior. Everything seems to work well, and now that we're implementing Amazon Pay thanks to Matt Glaman, I'm probably glad that we've fixed this sooner than later :)
Comment #7
rszrama CreditAttribution: rszrama at Centarro commentedGreat, thanks for the extra info. Was just committing the patch, will try to remember to call out the update in the release notes. : D
Comment #8
torgosPizzaHappy to help. I'm actually somewhat surprised we had not seen this issue until now, but I suspect having two offsite payment gateways made the bottleneck a little more visible.
Thanks!
Comment #9
rszrama CreditAttribution: rszrama at Centarro commentedJust realized we should likely wrap these in db_index_exists() checks. Only thought of it b/c I was reviewing some other local code where I'd written an update function to make that check in case someone already added the index.
Comment #10
torgosPizzaThat's probably a good idea, just in case anyone's already thought of this.
Comment #11
torgosPizzaNew patch attached rolled against Dev.
Comment #13
rszrama CreditAttribution: rszrama at Centarro commentedGroovy, thanks! Beat me to it. : D