performance - Speeding up a MySQL stored routine -


I was thinking that it is possible to speed up the MySQL query. Currently, I'm calling it 20,000 times, and it takes a while to run (about 10 to 20 minutes for a while).

Here is the basic table layout: DB1: INT (11) ID VARCHAR (45) Call 1 VARCHAR (100) Cola 2 VARCHAR (100) Cole 3 dB 2: VARCHAR (45) ID DB3: VARCHAR (45) fk_db2 INT (11) fk_db1

Here is the stored routine:

DELIMITER $$ DEFINER = 'Route' @ 'Localhost' process' proc` (INFK VARCHAR (45), in a VAARAR (45), INB VARCHAR (100), IN C VARCHAR (65)) BEGIN SET @ id = 0; SELECT id to @ID to DB1 WHERE db1.col1 = an AND db1.col2 = b and db1.col3 = c; If the ID = 0 = then enter the value in DB1 (call1, cola2, col3) (A, B, C); SELECT LAST_INSERT_ID () on IID @id; end if; - Enter the Association DB3 (fk_db1, fk_db2) values ​​(IID, FK) for DB2 and DB1; END

The main point of this routine, do I want to get an ID of a specific record, or if one does not exist then want to make one. Then I want to associate that FK and the ID that I just came to know. I'm sure there is a MySQL one-liner for this, but I'm unable to understand it.

Any help is appreciated !!

Thank you!

Well, the names of columns in the actual database are much better, but I can not share the name with you.

Actually, unless I am missing something, it does not slow down, do you see something Can you define "take a while" in "a while"?

Do you have an index on col1 / col2 / col3?

How are you telling the process in your application? You are reusing the database connection, right?

Can you bundle multiple calls in a single deal if you are not already?


Comments