We have a couple servers, one test server, and another production server.
The table schemas, indexes, and data are identical on both.
Here is the table schema:
create table service_environment_dependency_index (
service_id int unsigned default 0 not null,
environment_id smallint unsigned default 0 not null,
depends_on_service_id int unsigned default 0 not null,
depends_on_environment_id smallint unsigned default 0 not null,
primary key (service_id, environment_id, depends_on_service_id, depends_on_environment_id)
) charset = latin1;
create index depends_on_service_fields
on service_environment_dependency_index(depends_on_service_id, depends_on_environment_id);
create index service_fields
on service_environment_dependency_index(service_id, environment_id);
And here is the query in question:
INSERT IGNORE INTO service_environment_dependency_index (
service_id,
environment_id,
depends_on_service_id,
depends_on_environment_id
) (
SELECT one.service_id
, one.environment_id
, two.depends_on_service_id
, two.depends_on_environment_id
FROM service_environment_dependency_index one
INNER JOIN service_environment_dependency_index two
ON one.depends_on_service_id = two.service_id
AND one.depends_on_environment_id = two.environment_id
);
I know that query should take a bit, and it does on the test server, with some queries (accessing 750k rows) taking ~4 min.
The issue is that on the production server, the same query, with the same table schema, and same data, takes ~2 hours.
What possible causes could there be for an identical query taking 30x as long?
I ran SHOW VARIABLES;
on both servers, and they both are pretty close to identical with the production server having some larger pool values:
(Here are some of the different variables **
as well as some possibly related other variable values)
Both servers are running 10.4.8-MariaDB-log
. Both servers give the following EXPLAIN
for the query posted:
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
---|---|---|---|---|---|---|---|---|---|
1 | SIMPLE | two | index | PRIMARY,ids | PRIMARY | 12 | NULL | 1056208 | Using index; Using temporary |
1 | SIMPLE | one | ref | depends_on | depends_on | 6 | two.service_id,two.environment_id | 8 | Using index |
Both tables are InnoDB.
EXPLAIN SELECT ...
portion of queries from test and prod? Which mariadb version(s) (are test and prod the same?)?SHOW CREATE TABLE service_environment_dependency_index
)