MySQL: OR versus UNION Ė which is faster?

Published on Mar 24, 2014 by Jamie Munro

I must say, this came as a shock to me, until I looked at the results and thought about it for a minute.† Before jumping in, let me explain how and where I encountered this.† I was recently working on a project called Deja Scene Ė The actor to actor movie database.† The purpose of this site is to find two actors who have starred in multiple movies together.

Because the nature of the algorithm an actor can be either on the left side of the connection or the right side.

Letís look at an example, if I search for George Clooney, I will find that he has 372 Deja Scene connections.† Here was the original query I used to retrieve the list of his connections:



SELECT *

FROM† `actor2_actors`

WHERE actor1_id =1

OR actor2_id =1



Seems pretty straight forward; however, I was seeing really slow performance and I couldnít figure out why.† I created an index on both the actor1_id and the actor2_id, so I assumed Mysql was properly indexing this.† Boy was I wrong.† Look at the results when I use the EXPLAIN function:

Read more >

Tags: SQL | Optimization | performance | mysql

Three-month work-life retrospective

Published on Sep 11, 2013 by Jamie Munro

Just over three months ago, I posted a few memorable blogs (for me) in regards to a career change.† The career change has been made and I thought I would share my retrospective on how it has affected me.

Following the format of the retrospectives I have been over the past 3 months, Iíll start with a check in word:

Rejuvenated

Making the move from an 85% managerial role to a 100% development role has completely rejuvenated me.† In the past three months I have gained an incredible amount of knowledge and furthered myself as a person and a developer.

Moving along to the next items:

  • What do I want to stop doing?

  • What do I want to start doing?

  • What do I want to continue doing?


Read more >

Tags: Optimization | stress | Theory | Rants | agile | scrum | retrospective

Iím hooked on test-driven development (TDD)

Published on Aug 6, 2013 by Jamie Munro

Iíve only been doing TDD for a few weeks, but Iím completely sold.† I donít want to go back!† Iíll be honest though, it hasnít been easy.† Iíve made mistakes, Iíve wasted time, but Iím really starting to reap the benefits.

Iíve always thought I was a good developer.† I write decent code and it works mostly as expected.† It took me many years into my career before I wrote my first unit test.† It always fell into the category of too time consuming or expensive.† Oh the irony!

As I started learning how to write to unit tests, I always found myself rewriting things I already did just to get them to be unit tested; how frustrating!† A unit test that should have only took a few minutes, ended up taking a really long time because the code had to be refactored just to be tested.† No better way to turn you off from unit testing.

Enter test-driven developmentÖ

Read more >

Tags: Optimization | ASP.NET | Theory | fizzbuzz | tdd | test-driven development

If You Don't Start You Won't Finish

Published on Jun 13, 2013 by Jamie Munro

I really wish that I didnít need to tell myself this 5 to 10 times a day, but unfortunately itís always just too easy to not start.

If you donít have kids, you truly have no understanding of how many toys they have and how much of a mess they make.† If you only have 1 kid, itís probably a lot, but Iíve been blessed with 3 Ė and let me tell you that each and every day there is at least 10 to 15 minutes of clean up in every room!

The honest truth of the matter is though, if I donít start, it wonít get done Ė unlike the story about the Shoemaker and the Elves, they are not coming to clean my house each day!

This of course is a very simple example, but I find this reminder useful even at work.

Read more >

Tags: Optimization | stress | Theory | Rants | agile | lazy

What Do You Care Most About When Reviewing Someone Elseís Code?

Published on Jun 10, 2013 by Jamie Munro

I wrote an article a few months ago called Compelling Interview Questions where buried deep in the middle under several open-ended technical questions I asked the question ďWhat Do You Care Most About When Reviewing Someone Elseís Code?Ē

The funny part about this when you read a few lines below I follow it up with Iím not looking for anything in particular; just some generic catch-phrases that most people throw out there.† E.g. properly indented code, no large comment blocks, documentation to explain a complex block of code, etcÖ

Ask me today what I expect from this question and my answer is totally different!† Today being as I write this article Ė ask me in the present and letís see if my answer changesÖ

Read more >

Tags: Optimization | php | socket server | PHP | interview | Rants | clean code

Developers are Authors

Published on Jun 6, 2013 by Jamie Munro

Automapper Performance Testing

Published on May 27, 2013 by Jamie Munro

Upgrading my Blog - The Final Saga!

Published on Sep 24, 2012 by Jamie Munro

Load Testing Mysql with mysqlslap

Published on Sep 17, 2012 by Jamie Munro

What I Learned This Summer

Published on Sep 7, 2012 by Jamie Munro

It's LEMP not LAMP!

Published on Sep 6, 2012 by Jamie Munro

PHP: Require/Include vs Autoloader

Published on Aug 29, 2012 by Jamie Munro

Optimizing CakePHP Websites

Published on Jan 20, 2010 by Jamie Munro

Caching Queries in CakePHP

Published on Apr 25, 2009 by Jamie Munro

The Importance of Database Indexing

Published on Feb 27, 2009 by Jamie Munro

Dynamic COUNT() Versus Static COUNT()

Published on Feb 24, 2009 by Jamie Munro

SQL Tips - Why LEFT JOINS are bad

Published on Feb 13, 2009 by Jamie Munro