Question

    SELECT 
      DISTINCT P.IDENTIFICATIONNUM IDNUMBER, 
      P.NAME NAME, 
      P.NATIONALITY NATIONALITY, 
      O.NAME COMPANY
    FROM APPLICANT_TB P
    LEFT JOIN APP_TB A ON A.APPLICANTID=P.APPLICANTID
    LEFT JOIN ORGANISATION_TB O ON O.ORGID = A.ORGID

as the sql code showing, i am using IBM DB2 , and according to explain plan , all the 3 tables are full table scan .can someone tell me how to avoid this ? (all the PK using are indexed)

Was it helpful?

Solution

Be more selective with the records you want. Include a WHERE clause.

OTHER TIPS

Since you are selecting all the rows the most efficient way to return those to you is to do table scans.

Even if you add filters you still may do table scans, that will depend on how well your indexes match to the columns you are filtering on, and how up-to-date the database statistics are.

In general the query optimizer will guess the percentage of the table it needs based on you filter. Once that percentage goes over a certain (surprisingly small like 20%) portion of the table, it will choose a table scan as the "best" way to get the data you are asking for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top