I have two tables: A - 301 columns (the first named a1 int (11) Primary key, from 2nd to 301th - double (15.11)) and columns B-33 (1st number - b1 int (11) Unique Key, 2nd One - b2 varchar (100) Primary key, ..., 33rd - b33 int (11) MUL).
Both A and B have ~ 13.5 million entries.
My mysql query: for each pos value, with pos in the set (1, 1000, 2000, ..., 13500000) in thousands of 1000:
select A. *, b2, b5, b7, b8, b10, b13, b33 from A join B to a1 = b1, where b33> = pos and b33 <pos + 1000;
The request takes 1-5 seconds for the values b33 <= 600,000. After that, the request starts from 20-30 seconds. When b33> = 8,000,000, the request starts from 60-70 seconds. I can not understand why the slowdown occurs. b33 is indexed, and joining occurs by a key that is defined as primary in one table and unique in another. Is there a workaround for this? This really hinders the speed of the code, and I will have to split tables A and B into several smaller ones if nothing works. I really hope I don’t need to do this! Please, help!
EDIT: Here is o / p EXPLAIN -
************* 1. *************
id: 1
select_type:
: B
:
possible_keys: b1, b33
: b33
key_len: 4
ref: NULL
: 981
:
************* 2. *************
id: 1
select_type:
: A
: eq_ref
possible_keys:
: PRIMARY
key_len: 4
ref: DBName.B.b1
: 1
:
2 (0,00 )