What Indexes Would Speed this MySQL Statement -


i need change tables have in database can store more information against particular item, supplier. have 1 table follows:

product (~285000 rows)

  • product_id
  • supplier_name
  • barcode
  • ...

and want create 2 more tables:

supplier:

  • supplier_id (uuid)
  • name (from product table)
  • contact
  • ...

supplier product:

  • product_id (product fk)
  • supplier_id (supplier fk)
  • delivery option
  • ...

the supplier table needs filled distinct entries supplier_name in product table. supplier_product table needs uuid supplier table.

my sql far is:

insert supplier (name, id) select distinct(trim(supplier)), uuid() product supplier_name not null , trim(supplier_name) != "" , trim(supplier_name) not in (     select name supplier ); 

creates ~4000 rows. then:

insert supplier_product (id, supplier_id, product_id, barcode, ...) select uuid(), s.id, p.product_id, p.barcode, ...   product p   inner join supplier s on trim(p.supplier_name) = s.name   s.name not null; 

the query timing out after 30 seconds. there better way populate these 2 tables?

creating more tables pattern i've run across appreciate advice if there more optimal way.

i added index on name column in supplier table , no longer seeing timeouts. can drop index after insert has run.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -