[MDEV-30196] different character set than expected makes stored procedure run 100 times slower Created: 2022-12-11  Updated: 2023-04-03  Resolved: 2023-04-03

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.10.2
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Philip orleans Assignee: Unassigned
Resolution: Incomplete Votes: 0
Labels: None
Environment:

Linux



 Description   

In Debian 11, when I create a table using
mysql database -e "create table xyz(field1 int not null )" it gets automatically
CHARACTER SET utf8mb4,
COLLATE utf8mb4_general_ci;
BUT: if I create stored procedure the same way, for example:

SQL="DELIMITER \$\$

CREATE DEFINER = 'root'@'%'
PROCEDURE generate_npadata(IN flagv VARCHAR(1))
BEGIN
DECLARE strv varchar(7);
DECLARE done int DEFAULT FALSE;
DECLARE npanxxv varchar(7);
DECLARE statev varchar(2);
DECLARE companyv varchar(30);
DECLARE ocnv varchar(4);
END
\$\$

DELIMITER ;"

mysql database -e "${SQL}"
it gets character_set_client=latin1
collation_connection=latin1_swedish_ci

and that is a tragedy, since in this scenario, this store procedure runs 100 times slower than the same exact stored procedure, bit by bit, if the character_set_client and the collation_connection were= utf8mb4_general_ci

This should not happen. If I can do a " create table" from bash script and get
CHARACTER SET utf8mb4,
COLLATE utf8mb4_general_ci;
then I should get the same if I create any stored procedure, ceteris paribus.
I am using
Server version: 10.10.2-MariaDB-1:10.10.2+maria~deb11 mariadb.org binary distribution
Not the Debian distribution which is way behind.

This is two bugs for the price of one. The first is to make sure that a Stored Procedure gets the right character set, and the second is: even if the character set is different than the table or the database collation, that stored procedure should not run 100 times slower, and I am not exaggerating.
My stored procedure is reading from a table in a loop, and the tables can be engine=memory, it makes no difference.

I can provide root access to Helena to my development box so she can verify the facts.
Or I can send her the data and the bash script that duplicates the issue.



 Comments   
Comment by Sergei Golubchik [ 2023-01-04 ]

What stored procedure is running 100 times slower? Literally, this one?

CREATE DEFINER = 'root'@'%'
PROCEDURE generate_npadata(IN flagv VARCHAR(1))
BEGIN
DECLARE strv varchar(7);
DECLARE done int DEFAULT FALSE;
DECLARE npanxxv varchar(7);
DECLARE statev varchar(2);
DECLARE companyv varchar(30);
DECLARE ocnv varchar(4);
END

But it doesn't do anything.Do you have a realistic example of a stored procedure that's 100 times slower?

Comment by Sergei Golubchik [ 2023-01-04 ]

if you read data in a loop, them you might also be affected by MDEV-29988. If this is the case, the next release should fix this 100x slowdown.

Comment by Elena Stepanova [ 2023-02-05 ]

Or I can send her the data and the bash script that duplicates the issue.

Please do.

Comment by Philip orleans [ 2023-02-05 ]

Will be sending you credentials for a blank machine where you may see the issue

Yours
Federico

Comment by Elena Stepanova [ 2023-02-05 ]

philip_38
I'd very much prefer the data and the script, as you said. Thanks.

Comment by Sergei Golubchik [ 2023-03-06 ]

philip_38, normally we close the issue as "incomplete" if it stays in the "needs feedback" state for a month.
Now this my comment resets the timer, so the issue will stay open for another month, in case you'll want to reply.

Comment by Philip orleans [ 2023-04-03 ]

Please close it.
Just by using the char set, everything works fine.

Generated at Thu Feb 08 10:14:25 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.