how to rewrite not Exists( select * from tmpsegmdafinnull where…
- User
how to rewrite not Exists( select * from tmp_segm_dafin_null where TMP_T38ESEGMENTATION.no_pse=tmp_segm_dafin_null.no_pse and tmp_segm_dafin_null.cd_modele=TMP_T38ESEGMENTATION.cd_modele ); without not in select
- Assistant
Exists( select * from tmp_segm_dafin_null where TMP_T38ESEGMENTATION.no_pse=tmp_segm_dafin_null.no_pse and tmp_segm_dafin_null.cd_modele=TMP_T38ESEGMENTATION.cd_modele ) = 0
- Assistant
The rewritten code is:
Exists( select * from tmp_segm_dafin_null where TMP_T38ESEGMENTATION.no_pse=tmp_segm_dafin_null.no_pse and tmp_segm_dafin_null.cd_modele=TMP_T38ESEGMENTATION.cd_modele ) = False
- User
how to rewrite not Exists( select * from tmp_segm_dafin_null where TMP_T38ESEGMENTATION.no_pse=tmp_segm_dafin_null.no_pse and tmp_segm_dafin_null.cd_modele=TMP_T38ESEGMENTATION.cd_modele ); for faster execution in large database
- Assistant
One way to potentially speed up the execution is to use a LEFT JOIN instead of NOT EXISTS:
SELECT TMP_T38ESEGMENTATION.* FROM TMP_T38ESEGMENTATION LEFT JOIN tmp_segm_dafin_null ON TMP_T38ESEGMENTATION.no_pse=tmp_segm_dafin_null.no_pse AND tmp_segm_dafin_null.cd_modele=TMP_T38ESEGMENTATION.cd_modele WHERE tmp_segm_dafin_null.no_pse IS NULL
This query uses a LEFT JOIN to join the two tables based on the condition you provided. The WHERE clause filters out the rows where there is a match in the joined table (i.e. tmp_segm_dafin_null.no_pse is not null), effectively returning the same rows as the original NOT EXISTS condition.
Using a LEFT JOIN may be faster than NOT EXISTS because it allows the database to use an index on the join condition, while NOT EXISTS requires a full table scan of the subquery, which can be slower for large tables. However, as with any query optimization, it is recommended to test the performance on your specific database and data set before implementing it in production.