بتاريخ: 29 مايو 200619 سنة comment_70683 I have problem with the execution of below SQL command; it take a lot of time; when I checked the execution plan show me that it make the full table scan because I am using (NOT IN)Please advice me if you have idea regarding this issue.============== select t1.aa from t1 where t1.c not in ( select t2.c ( from t2 note that there is index on the FK ============== تقديم بلاغ
بتاريخ: 30 مايو 200619 سنة comment_70713 NOT IN و INمن احد اعداء optimizer ولن تجعله يقوم باستخدام index وعوض عنها بامكانك استخدام !=لاحظ من المثال التي كيف الفرق وخاصه في Cost و الوقت select id from .t1 where id not in (select id from .t2); --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1379K| 9429K| 2255K (1)| 07:31:06 | |* 1 | FILTER | | | | | | | 2 | TABLE ACCESS FULL| T1 | 1379K| 9430K| 4374 (2)| 00:00:53 | |* 3 | TABLE ACCESS FULL| T2 | 1 | 7 | 2 (0)| 00:00:01 | --------------------------------------------------------------------------- select id from t1 where id !=(select id from t2); ---------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 68974 | 471K| 653 (4)| 00:00:08 | |* 1 | INDEX FAST FULL SCAN| T1_ID_IDX | 68974 | 471K| 651 (4)| 00:00:08 | | 2 | TABLE ACCESS FULL | T2 | 1 | 7 | 2 (0)| 00:00:01 | ---------------------------------------------------------------------------------- تقديم بلاغ
بتاريخ: 30 مايو 200619 سنة كاتب الموضوع comment_70724 اشكرك يا ابوصالح على استجابتك السريعة ، ولكن المشكلة انه لا يمكن استخدام != لأن subquery يرجع اكثر من قيمة single-row subquery returns more than one row تقديم بلاغ
بتاريخ: 30 مايو 200619 سنة كاتب الموضوع comment_70731 لقد قمت باستخدام NOT EXISTS عوضاً عن NOT IN وهو نوعاً ما افضل تقديم بلاغ
انضم إلى المناقشة
يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.