0

This DB is running in a cluster.

Insert/Update queries are taking more than 30ms to execute. Select queries are quick with less than 5ms.

We are already following this guide: here

From Laravel Query Log time is in (ms):

array (
    'query' => 'insert into legacy_item_requests (request) values (?)',
    'bindings' => 
    array (
      0 => 1,
    ),
    'time' => 38.91,
  ),

Direct Insert in MySQL:

enter image description here

Show create table:

CREATE TABLE `legacy_item_requests` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `request` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

The insert is happening on an empty table which is puzzling.

We are using: Server version: 5.7.28-31-57 Percona XtraDB Cluster (GPL), Release rel31, Revision ef2fa88, WSREP version 31.41, wsrep_31.41

Laravel 9.9.0
PHP 8.0.18

My question here is how do I diagnose this and figure out what's causing the slow insert/update?

Note that this insert is part of a big transaction and I can't do BEGIN and COMMIT because it causes a deadlock due to the sheer size of the transaction.

I can provide config details if needed

Show Profile Result

enter image description here

enter image description here

On a different MySQL server the insert took 0ms so we're wondering what's the difference considering the one with the 39ms is a bigger server. What other factors will affect the insert query?

5
  • Inserts being a modification are required to be durable, hence requiring a waiting of acknowledgement back all the way from hardware to indicate it has been stored. So being slower than select is expected. Deadlocks happens if the acquisition of locks is in a different order. Maybe there is some way to optimize the large transaction.
    – danblack
    Commented Apr 27, 2022 at 4:11
  • Tested on MariaDB-10.6, admittedly the 3 nodes where all local, and got this profile for the same query. I'd suggest taking it to percona to see if they can improve that region of code. Or consider a MariaDB migration.
    – danblack
    Commented Apr 27, 2022 at 6:23
  • @danblack what is initiating replication for? tried googling it but can't find any reference. Commented Apr 27, 2022 at 6:24
  • 1
    It would be in the code probably under PSI_stage_info or similar, I can't find it right now. What it exactly is would involve understanding the code up until the next stage. You may be able to map the concept to this galera certification flow.
    – danblack
    Commented Apr 27, 2022 at 7:02
  • How far apart are the Galera nodes? (That is, ping time.) Was this INSERT the first after a reboot? If so, possibly there are some one-time startup actions. Or does the Laravel Insert repeatedly take a long time?
    – Rick James
    Commented Apr 27, 2022 at 22:13

1 Answer 1

-3

Might be that you have too many indexes, or redundant indexes. You can use tools like EverSQL.com to find these indexes.

You can also run select 1; to see if you have any network latency.

Disclosure, I am the co-founder of EverSQL

2
  • We require disclosure when you promote a product you are affiliated with see dba.stackexchange.com/help/promotion. Please read that page carefully before posting again.
    – Paul White
    Commented Apr 27, 2022 at 7:08
  • Redundant non-unique indexes do not slow down INSERTs; they go into the "change buffer" for eventual storing on disk.
    – Rick James
    Commented Apr 27, 2022 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.