Changing SQL NOT IN to JOINS -


enter image description here

hello guys,

our aim script insert missing pairs of product - taxcategory in intermediate table (producttaxcategory)

the following script correctly working trying find way optimize it:

insert producttaxcategory     (producttaxcategory_taxcategoryid,producttaxcategory_productid) select      taxcategoryid     ,productid  product pr cross join taxcategory tx pr.productid not in  (     select producttaxcategory_productid     producttaxcategory )  or pr.productid in  (     select producttaxcategory_productid      producttaxcategory )  , tx.taxcategoryid not in  (     select producttaxcategory_taxcategoryid      producttaxcategory      producttaxcategory_productid = pr.productid  ) 

how can optimize query ?

try (full statement now):

insert producttaxcategory     (producttaxcategory_taxcategoryid,producttaxcategory_productid) select taxcategoryid, productid  product pr cross join taxcategory tx not exists        (select 1 producttaxcategory          producttaxcategory_productid     = pr.productid         ,   producttaxcategory_taxcategoryid = tx.taxcategoryid) 

exists (select 1 ... id=...) better alternative in (select id ... ) constructs.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -