[MDEV-27453] Performance degredation when IN elements are string instead of int Created: 2022-01-09  Updated: 2022-06-11  Resolved: 2022-01-10

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.5.12, 10.6.8
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Panagiotis Malakoudis Assignee: Sergei Golubchik
Resolution: Duplicate Votes: 0
Labels: None
Environment:

Debian 11


Attachments: File test.sql    
Issue Links:
Duplicate
is duplicated by MDEV-27380 After minor upgrade to 10.5.13 querie... Closed

 Description   

I upgraded from Debian 10 to Debian 11. Debian 10 had mariadb 10.3.31 and Debian 11 has mariadb 10.5.12.
Since the upgrade, queries with IN statement that include single quoted numbers (making them text instead of int) have very lower performance.

I attach two example queries, one with quotes, one without. I will write them here cut down, with the explain output for both mariadb 10.3.31 and 10.5.12

10.3.31 with quotes
explain SELECT * FROM video
WHERE id in ('1283','1284','1298', [ about 14000 ids deleted] , '105149','105152','105153')
LIMIT 0, 14;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE video range PRIMARY PRIMARY 4 NULL 14488 Using where
takes 0.05 sec

10.3.31 without quotes
explain SELECT * FROM video
WHERE id in (1283,1284,1298, [ about 14000 ids deleted] , 105149,105152,105153)
LIMIT 0, 14;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY video ALL PRIMARY NULL NULL NULL 14898
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 14488
3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used
takes about 0.01 sec

10.5.12 with quotes
explain SELECT * FROM video
WHERE id in ('1283','1284','1298', [ about 14000 ids deleted] , '105149','105152','105153')
LIMIT 0, 14;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE video ALL PRIMARY NULL NULL NULL 14889 Using where
Takes about 2,3 seconds

10.5.12 without quotes
explain SELECT * FROM video
WHERE id in (1283,1284,1298, [ about 14000 ids deleted] , 105149,105152,105153)
LIMIT 0, 14;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY video ALL PRIMARY NULL NULL NULL 14889
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 14488
3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used
takes 0.01 sec

So the first problem is the different optimization for the query with the quotes, resulting in 2,3 seconds execution instead of 0,05 seconds in mariadb 10.3.31. 10.3.31 uses range while 10.5.12 does not. Second problem is that mariadb is not doing IN predicate for single quoted integers, although I thought that MDEV-21265 solved this (apparently it didn't).



 Comments   
Comment by Sergei Golubchik [ 2022-01-10 ]

This is being fixed as MDEV-27380

Comment by Panagiotis Malakoudis [ 2022-06-11 ]

I still have the reported issue with 10.6.8-MariaDB-1:10.6.8+maria~bullseye mariadb.org binary distribution
from the official mariadb repository installed on Debian 11.
Query with quotes on numeric values takes 2,5 seconds while without quotes on numeric values is finishing instantly. Which binary distribution from the official mariab repository fixes this issue please?

Generated at Thu Feb 08 09:53:01 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.