re-write not Exists( select * from tmpsegmdafinnull where…
- User
re-write 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 select in not in
- Assistant
NOT EXISTS ( SELECT 1 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 );
- 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
To potentially speed up the query for large databases, you can:
- Use EXISTS with SELECT 1 instead of SELECT * to avoid retrieving unused columns:
NOT EXISTS ( SELECT 1 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)-
Make sure there are appropriate indexes on the columns used in the JOIN condition (no_pse, cd_modele) to speed up the JOIN operation.
-
Another option is to rewrite the query using a LEFT JOIN with a WHERE clause:
SELECT ... -- (list the columns you need) FROM TMP_T38ESEGMENTATION LEFT JOIN tmp_segm_dafin_null ON TMP_T38ESEGMENTATION.no_pse = tmp_segm_dafin_null.no_pse AND TMP_T38ESEGMENTATION.cd_modele = tmp_segm_dafin_null.cd_modele WHERE tmp_segm_dafin_null.no_pse IS NULL AND tmp_segm_dafin_null.cd_modele IS NULL;Depending on the database and the distribution of data, the LEFT JOIN query might perform better than the NOT EXISTS query. However, you should test both queries on your specific database to see which one performs better. Don't forget that indexes are important for better performance, so it is advisable to create them on the appropriate columns.