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

Advanced Automatic Ninject Bindings

Published on Jan 13, 2014 by Jamie Munro

Problem


You have a common interface that is used by multiple concrete classes and you don’t want to specify each Ninject binding manually.

Solution


The solution to this problem is very similar to my previous post on Automatic Ninject Bindings because it also leverages the NuGet package Ninject.extensions.conventions.

In this example, let’s assume you have a single interface called IService<T>.  This interface contains a generic reference to a class or object (e.g. a database model).  Then you have multiple classes that implement the interface.  E.g. UserService : IService<User>.

With the following line of code, all of your classes that implement the IService interface will automatically bind to the corresponding class:


             var kernel = new StandardKernel();

             kernel.Bind(x =>

             {

                 x.FromThisAssembly()

                     .SelectAllClasses()

                     .InheritedFrom(typeof(IService<>))

                     .BindSingleInterface();

             });

 

Read more >

Tags: Uncategorized | ASP.NET | c# | mvc | ninject

Automatic Ninject Bindings

Published on Jan 7, 2014 by Jamie Munro

Problem


You have a large project with many interfaces and many different concrete implementations.  Because of this, managing every single Ninject binding is becoming challenging and time consuming.

Solution


By leveraging an additional Ninject NuGet package called Ninject.extensions.conventions, you can write a single line (wrapped over several for readability ;) that will manage all of your Ninject bindings.


 IKernel kernel = new StandardKernel();



 kernel.Bind(x =>

 {

    x.FromThisAssembly()

    .SelectAllClasses()

    .BindDefaultInterface();

 });


Read more >

Tags: ASP.NET | c# | mvc | ninject

How I overcame my anxieties

Published on Oct 19, 2013 by Jamie Munro

Like millions of regular people, I have anxieties.  I have a rough time sleeping, I stress, and I get depressed.  Very typical behavior for many people.

Rather than pretending these issues were not real, I built an Android application and met them head on!  I created Behavior Therapy Tracker and through its constant use I was able to overcome many of my anxieties.

Let me explain my story and I hope it can help you as much as it has helped me.

Read more >

Tags: stress | Theory | android | Android | behavior

Android ListView with a Footer Form

Published on Sep 26, 2013 by Jamie Munro

During the creation of my first Android application – Behavior Therapy Tracker – I wanted to display a list of behaviors to manage; more importantly though, I wanted an easy way for users to add new behaviors to the list.

My solution to this problem was simple, add a one-liner form to the footer of my ListView that contained the behaviors.

Read more >

Tags: android | Android | Java | listview | linearlayout | relativelayout

Three-month work-life retrospective

Published on Sep 11, 2013 by Jamie Munro

Behavior Therapy Tracker

Published on Sep 1, 2013 by Jamie Munro

Finding That Inner Calm

Published on Jun 18, 2013 by Jamie Munro

If You Don't Start You Won't Finish

Published on Jun 13, 2013 by Jamie Munro

Setting Up CakePHP with IIS

Published on Jun 11, 2013 by Jamie Munro

Developers are Authors

Published on Jun 6, 2013 by Jamie Munro

My Epic Farewell Poem

Published on May 30, 2013 by Jamie Munro

Slowing Down Before You Speed Up

Published on May 29, 2013 by Jamie Munro

My Favorite Thing About Coldfusion

Published on May 28, 2013 by Jamie Munro

Automapper Performance Testing

Published on May 27, 2013 by Jamie Munro

Should I Leave My Job?

Published on May 24, 2013 by Jamie Munro

Why the Repository Pattern

Published on May 20, 2013 by Jamie Munro

Why is my calendar always full?

Published on May 15, 2013 by Jamie Munro

Simple Things Make Me Happy

Published on May 14, 2013 by Jamie Munro

Compelling Interview Questions

Published on Apr 25, 2013 by Jamie Munro

Recent Guest Posts on PHPMaster.com

Published on Jan 7, 2013 by Jamie Munro

2012 Year in Review

Published on Dec 21, 2012 by Jamie Munro

Google Event Tracking

Published on Oct 5, 2012 by Jamie Munro

My First Node Application

Published on Oct 4, 2012 by Jamie Munro

Regular Expressions with Mysql

Published on Oct 2, 2012 by Jamie Munro

Mysql Uptime Check Script

Published on Oct 1, 2012 by Jamie Munro

Renaming a Database in Mysql

Published on Sep 28, 2012 by Jamie Munro

Using Jquery to Check a Checkbox

Published on Sep 27, 2012 by Jamie Munro

A Fancier Twitter Timeline

Published on Sep 25, 2012 by Jamie Munro

Upgrading my Blog - The Final Saga!

Published on Sep 24, 2012 by Jamie Munro

The Best Way to Prevent SQL Injection

Published on Sep 19, 2012 by Jamie Munro

CakePHP 2.x Login System

Published on Sep 18, 2012 by Jamie Munro

Load Testing Mysql with mysqlslap

Published on Sep 17, 2012 by Jamie Munro

A Short Rant About Coding Conventions

Published on Sep 13, 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

Amazon EC2 Shoutout!

Published on Sep 5, 2012 by Jamie Munro

PHP: Require/Include vs Autoloader

Published on Aug 29, 2012 by Jamie Munro

2011: Year in Review

Published on Jan 2, 2012 by Jamie Munro

MVC 3 Routing Example

Published on Oct 17, 2011 by Jamie Munro

20 Recipes for Programming MVC 3

Published on Oct 12, 2011 by Jamie Munro

Officially published my CakePHP Book

Published on May 19, 2011 by Jamie Munro

AJAX Star Rating Plugin For CakePHP

Published on Mar 2, 2011 by Jamie Munro

IBM's Watson On Jeopardy!

Published on Feb 16, 2011 by Jamie Munro

Publishing an e-book on Smashwords

Published on Feb 7, 2011 by Jamie Munro

CakePHP 2.0 Rant Retraction

Published on Feb 1, 2011 by Jamie Munro

CakePHP 2.0 Rant

Published on Jan 31, 2011 by Jamie Munro

Random Funny Technology Videos

Published on Jan 27, 2011 by Jamie Munro

Using the TextHelper with CakePHP

Published on Jan 24, 2011 by Jamie Munro

Maintaining the back button with AJAX

Published on Dec 28, 2010 by Jamie Munro

AJAX, can there be too much?

Published on Dec 22, 2010 by Jamie Munro

Making Money With Flash Games

Published on Jun 27, 2010 by Jamie Munro

iPhone Apps Randomly Crashing?

Published on Feb 4, 2010 by Jamie Munro

Optimizing CakePHP Websites

Published on Jan 20, 2010 by Jamie Munro

Adding SEO functionality

Published on Nov 15, 2009 by Jamie Munro

unbindModel and $this->paginate()

Published on Aug 20, 2009 by Jamie Munro

Someone at work tick you off?

Published on Jul 28, 2009 by Jamie Munro

Follow me on Twitter

Published on Jun 19, 2009 by Jamie Munro

Sharing your way to success

Published on Jun 6, 2009 by Jamie Munro

Photobucket, Photos, and You

Published on May 23, 2009 by Jamie Munro

Facebook, Photos, and You!

Published on May 18, 2009 by Jamie Munro

Creating your first iGoogle Gadget

Published on May 12, 2009 by Jamie Munro

Bebo Development Scares Me

Published on May 7, 2009 by Jamie Munro

Caching Queries in CakePHP

Published on Apr 25, 2009 by Jamie Munro

Understanding group bys

Published on Apr 18, 2009 by Jamie Munro

ActivityIndicator with a UIWebView

Published on Apr 15, 2009 by Jamie Munro

Custom pagination query in CakePHP

Published on Apr 13, 2009 by Jamie Munro

3 Flaws to CakePHP's AuthComponent

Published on Apr 10, 2009 by Jamie Munro

The flaws of using isset()

Published on Apr 8, 2009 by Jamie Munro

Reset UINavigationController

Published on Apr 6, 2009 by Jamie Munro

Scroll a UIWebView

Published on Apr 4, 2009 by Jamie Munro

Transparent UIWebView

Published on Apr 2, 2009 by Jamie Munro

A friendly framework reminder

Published on Apr 1, 2009 by Jamie Munro

Web Developers are Warriors

Published on Mar 30, 2009 by Jamie Munro

Unbind Model Validation in CakePHP

Published on Mar 28, 2009 by Jamie Munro

Jquery vs Prototype/Scriptaculous

Published on Mar 26, 2009 by Jamie Munro

How attentive are you?

Published on Mar 25, 2009 by Jamie Munro

Re-map key/value array data in PHP

Published on Mar 19, 2009 by Jamie Munro

How to deal with stress at work

Published on Mar 17, 2009 by Jamie Munro

Underscores and Internet Explorer Fun

Published on Mar 13, 2009 by Jamie Munro

How to advance our CMS in CakePHP

Published on Mar 8, 2009 by Jamie Munro

How to create a CMS with CakePHP

Published on Mar 7, 2009 by Jamie Munro

AJAX Select box in CakePHP

Published on Mar 6, 2009 by Jamie Munro

How to setup a route in CakePHP

Published on Mar 5, 2009 by Jamie Munro

A practical CASE Statement Example

Published on Mar 4, 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

Why You Should Always Backup

Published on Feb 22, 2009 by Jamie Munro

Why Frameworks Are Better

Published on Feb 17, 2009 by Jamie Munro

Why Is Internet Explorer Better?

Published on Feb 15, 2009 by Jamie Munro

Drag and Drop with AJAX Example

Published on Feb 14, 2009 by Jamie Munro

SQL Tips - Why LEFT JOINS are bad

Published on Feb 13, 2009 by Jamie Munro