Vin
Vin

Reputation: 169

How to optimize multiple joins

How do you guys optimize a query that has multiple joins because mine takes so much time?

    SELECT 
  * 
FROM
  (SELECT 
    MEMB.ACCT_N,
    MEMB.LAST_M,
    MEMB.MEMB_N,
    MEMB.MIDI_M,
    MEMB.STRT_D,
    MEMB.LAST_D,
    ACCT_M,
    PrintDate,
    RePrint 
  FROM
    MEMB 
    INNER JOIN ACCT 
      ON MEMB.ACCT_N = ACCT.ACCT_N 
    INNER JOIN Printing 
      ON MEMB.MEMB_N = Printing.MEMB_N
      INNER JOIN RePrinting 
      ON MEMB.MEMB_N = RePrinting.MEMB_N LIMIT 1000) AS MEMB ;

And also each table has the same length of MEMB_N of MEMB Table which has 70k data.

img1

img2

img3

EDIT: Added images of my table.

Upvotes: 1

Views: 60

Answers (1)

The Impaler
The Impaler

Reputation: 48770

A simple [initial] assessment will tell you the indexes you need to create. For example:

create index ix1 on acct (acct_n);

create index ix2 on printing (memb_n);

create index ix3 on reprinting (memb_n);

Upvotes: 2

Related Questions