Question : MySQL Temp table SLOW!

So I have this proc that is DEAD SLOW. It takes minutes to return. If I dont use a temp table, it takes about a tenth of a second.

Any clues?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `getCompanyOverviewV4`(
  IN iCk INT(10) ZEROFILL
)
BEGIN

    CREATE TEMPORARY TABLE IF NOT EXISTS filingIDTT (
        filingID INT
    );

    INSERT INTO filingIDTT (filingID)
    SELECT filingID
    FROM aggr_filings
    WHERE cik_issuer = iCIK;

    SELECT *
    FROM aggr_filings
    WHERE filingID IN (SELECT filingID FROM filingIDTT);

    SELECT *
    FROM aggr_transactions
    WHERE filingID IN (SELECT filingID FROM filingIDTT);

    SELECT *
    FROM ceostockwatch.aggr_owners
    WHERE filingID IN (SELECT filingID FROM filingIDTT);

    DROP TEMPORARY TABLE filingIDTT;

END

Answer : MySQL Temp table SLOW!

                 Hi!

Does your aggr_filingID have index on  the column cik_issuer ?
If not I would create an non-unique index on the columns (cik_issuer, filingID) which
would give you index-only scan/reading for the first query.
Then I would create or have an index on the column filingID the temporary table filingIDTT
like this

CREATE TEMPORARY TABLE IF NOT EXISTS filingIDTT (
        filingID INT, INDEX USING BTREE ( filingID)
    );

Hope this helps.

Regards,
      Tomas Helgi
Random Solutions  
 
programming4us programming4us