SQL Running Very Very Slowly?

I run this query on MSSQL successfully, however it does not run very well on MySql (query is being executed..). This is the first time MySQL has choked running a query. Also tried this on different computers both remote (LAN) and local db connections. MySQL Query Browser is not hanging or returning errors, just runs and runs until I cancel it!

Q. How can I increase code efficiency for MySQL?

Purpose: Insert only new records (no matching 'Logged' datetime's) into Secured table from the Main table Where Port (Ports table) is marked Secure

Also not using 'Group By' hoping it would speed things up.

Secured = tinyint(1)
Logged = datetime
Priority = varchar(50)
Port = varchar(10)

Insert into Secured (Cleared,Logged,Priority, Port)
 (SELECT 0, Logged,Priority, Port
  FROM Main m
  JOIN Ports p on p.Port = m.Port
  Where  p.Secure = '1'
  And m.Logged Not In (Select Logged From Secured)
  )
pointemanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
check out the EXPLAIN PLAN for the SELECT part of the query.
the main reason will be the NOT IN ( subselect )..

I would guess you don't have any index on "logged" column of Secured table ...
do that, and change also your query to:

Insert into Secured (Cleared,Logged,Priority, Port)
 (SELECT 0, Logged,Priority, Port
  FROM Main m
  JOIN Ports p on p.Port = m.Port
  Where  p.Secure = '1'
  And NOT EXISTS( Select null From Secured s WHERE m.Logged = s.Logged )
  )

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pointemanAuthor Commented:
I'm currently re-imaging the test computer in question. I'll let you know...
0
pointemanAuthor Commented:
Oops, sorry, didn't respond to you code answer. Okay. tried it without any better results...
0
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
explain plan, please ...
0
pointemanAuthor Commented:
Okay, here's the deal. I discovered that we are running MySQL 5.5.9 ... So, we re-imaged the drive and installed our ole reliabe 5.5.19 and everything is working fine.

NOTE: Before re-imaging, we reconfigured the 5.5.9 instance and the code I posted worked quick. However a few hours running and MySQL began to choke on the same code. I'm not sure where I download 5.5.9 anyway.. All is well.
0
pointemanAuthor Commented:
Excellent code example. I must note the problem was using MySQL 5.5.9 instead of 5.5.19 which we never have problems with.

Thanks...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.