Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6998051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:21:42+00:00 2026-05-27T20:21:42+00:00

I am having an odd issue and need some help determining the cause. So

  • 0

I am having an odd issue and need some help determining the cause. So far, I have only been able to observe the symptoms. What it “seems” is happening is that MySQL is executing the query different based on whether or not I have a newline character before my first “LEFT JOIN”.

Here is my setup:

I am running queries on a MySQL Database instance provided by http://www.xeround.com. I am using the Kohana framework, version 3.0. I am running PHP 5.3.3 FastCGI on Lighttpd. I compiled PHP with the MySQL Native Driver:

–with-mysql=mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd

I am using the default Kohana 3 MySQL Database Driver and QueryBuilder.

I am going to skip the PHP code and share the SQL since that seems to be the issue. The QueryBuilder ends up building this query:

SELECT `fieldreps`.`user_id` AS `fieldreps.user_id`, `fieldreps`.`availability_id` AS `fieldreps.availability_id`, `fieldreps`.`applicant_type` AS `fieldreps.applicant_type`, `fieldreps`.`license_number` AS `fieldreps.license_number`, `fieldreps`.`license_exp` AS `fieldreps.license_exp`, `fieldreps`.`license_state` AS `fieldreps.license_state`, `fieldreps`.`car` AS `fieldreps.car`, `fieldreps`.`authorized_worker` AS `fieldreps.authorized_worker`, `fieldreps`.`restrictions` AS `fieldreps.restrictions`, `fieldreps`.`night` AS `fieldreps.night`, `fieldreps`.`day` AS `fieldreps.day`, `fieldreps`.`longer` AS `fieldreps.longer`, `fieldreps`.`commitment` AS `fieldreps.commitment`, `fieldreps`.`travel_metro` AS `fieldreps.travel_metro`, `fieldreps`.`travel_states` AS `fieldreps.travel_states`, `fieldreps`.`big_employee` AS `fieldreps.big_employee`, `fieldreps`.`employed` AS `fieldreps.employed`, `fieldreps`.`retail` AS `fieldreps.retail`, `fieldreps`.`status` AS `fieldreps.status`, `fieldreps`.`start` AS `fieldreps.start`, `fieldreps`.`sales` AS `fieldreps.sales`, `fieldreps`.`study` AS `fieldreps.study`, `fieldreps`.`relevant` AS `fieldreps.relevant`, `fieldreps`.`experience` AS `fieldreps.experience`, `fieldreps`.`claims` AS `fieldreps.claims`, `fieldreps`.`education` AS `fieldreps.education`, `fieldreps`.`degree_details` AS `fieldreps.degree_details`, `fieldreps`.`degree_institution` AS `fieldreps.degree_institution`, `fieldreps`.`other_training` AS `fieldreps.other_training`, `fieldreps`.`jobs` AS `fieldreps.jobs`, `fieldreps`.`current_training` AS `fieldreps.current_training`, `fieldreps`.`interested` AS `fieldreps.interested`, `fieldreps`.`achievements` AS `fieldreps.achievements`, `fieldreps`.`passions` AS `fieldreps.passions`, `fieldreps`.`ambitions` AS `fieldreps.ambitions`, `fieldreps`.`max_travel_time` AS `fieldreps.max_travel_time`, `fieldreps`.`creation_time` AS `fieldreps.creation_time`, `fieldreps`.`resume` AS `fieldreps.resume`, `users`.`user_id` AS `users.user_id`, `users`.`email` AS `users.email`, `users`.`name` AS `users.name`, `users`.`password` AS `users.password`, `users`.`given_name` AS `users.given_name`, `users`.`title` AS `users.title`, `users`.`nationality` AS `users.nationality`, `availabilities`.`availability_id` AS `availabilities.availability_id`, `availabilities`.`fieldrep_id` AS `availabilities.fieldrep_id`, `availabilities`.`mon_start` AS `availabilities.mon_start`, `availabilities`.`mon_end` AS `availabilities.mon_end`, `availabilities`.`tue_start` AS `availabilities.tue_start`, `availabilities`.`tue_end` AS `availabilities.tue_end`, `availabilities`.`wed_start` AS `availabilities.wed_start`, `availabilities`.`wed_end` AS `availabilities.wed_end`, `availabilities`.`thur_start` AS `availabilities.thur_start`, `availabilities`.`thur_end` AS `availabilities.thur_end`, `availabilities`.`fri_start` AS `availabilities.fri_start`, `availabilities`.`fri_end` AS `availabilities.fri_end`, `availabilities`.`sat_start` AS `availabilities.sat_start`, `availabilities`.`sat_end` AS `availabilities.sat_end`, `availabilities`.`sun_start` AS `availabilities.sun_start`, `availabilities`.`sun_end` AS `availabilities.sun_end` FROM `fieldreps` AS `fieldreps` LEFT JOIN `users` ON (`fieldreps`.`user_id` = `users`.`user_id`) LEFT JOIN `availabilities` ON (`fieldreps`.`availability_id` = `availabilities`.`availability_id`)

Which returns a result like this:(I removed most of the fields returned from the Fieldreps table to keep it short and less personal.)

[0] => Array
    (
        [fieldreps.user_id] => 1f01f4c2-43fd-550d-a53d-1f191786ebad
        [fieldreps.availability_id] => e31b0773-ecba-41d1-8ebb-7ac718496456
        [fieldreps.car] => Yes
        [fieldreps.authorized_worker] => Yes
        [fieldreps.restrictions] => Has Restrictions: No 
        [fieldreps.night] => Yes
        [fieldreps.day] => Yes
        [fieldreps.longer] => Yes
        [users.user_id] => 1f01f4c2-43fd-550d-a53d-1f191786ebad
        [users.email] => dsfsdfsdfsdfsdfs@sdfsdfsdfsdfsd.com
        [users.name] => Jones
        [users.password] =>
        [users.given_name] => Fred
        [users.title] => Miss
        [users.nationality] => 
        [availabilities.availability_id] => 
        [availabilities.fieldrep_id] => 
        [availabilities.mon_start] => 
        [availabilities.mon_end] => 
        [availabilities.tue_start] => 
        [availabilities.tue_end] => 
        [availabilities.wed_start] => 
        [availabilities.wed_end] => 
        [availabilities.thur_start] => 
        [availabilities.thur_end] => 
        [availabilities.fri_start] => 
        [availabilities.fri_end] => 
        [availabilities.sat_start] => 
        [availabilities.sat_end] => 
        [availabilities.sun_start] => 
        [availabilities.sun_end] => 
    )
[1] => Array
    (
        [fieldreps.user_id] => 812c3a9f-d7d8-565a-a886-1b182753dd41
        [fieldreps.availability_id] => 
        [fieldreps.car] => 1
        [fieldreps.authorized_worker] => 1
        [fieldreps.restrictions] => 
        [fieldreps.night] => 1
        [fieldreps.day] => 1
        [fieldreps.longer] => 1
        [users.user_id] => 812c3a9f-d7d8-565a-a886-1b182753dd41
        [users.email] => sdfsdfsdfsdfsdf@sdfsdfsdfsdf.com
        [users.name] => Smith
        [users.password] => 
        [users.given_name] => Jill 
        [users.title] => 
        [users.nationality] => 
        [availabilities.availability_id] => 
        [availabilities.fieldrep_id] => 
        [availabilities.mon_start] => 
        [availabilities.mon_end] => 
        [availabilities.tue_start] => 
        [availabilities.tue_end] => 
        [availabilities.wed_start] => 
        [availabilities.wed_end] => 
        [availabilities.thur_start] => 
        [availabilities.thur_end] => 
        [availabilities.fri_start] => 
        [availabilities.fri_end] => 
        [availabilities.sat_start] => 
        [availabilities.sat_end] => 
        [availabilities.sun_start] => 
        [availabilities.sun_end] => 

However, when I insert a newline character immediately before the first LEFT JOIN, like this:

SELECT `fieldreps`.`user_id` AS `fieldreps.user_id`, `fieldreps`.`availability_id` AS `fieldreps.availability_id`, `fieldreps`.`applicant_type` AS `fieldreps.applicant_type`, `fieldreps`.`license_number` AS `fieldreps.license_number`, `fieldreps`.`license_exp` AS `fieldreps.license_exp`, `fieldreps`.`license_state` AS `fieldreps.license_state`, `fieldreps`.`car` AS `fieldreps.car`, `fieldreps`.`authorized_worker` AS `fieldreps.authorized_worker`, `fieldreps`.`restrictions` AS `fieldreps.restrictions`, `fieldreps`.`night` AS `fieldreps.night`, `fieldreps`.`day` AS `fieldreps.day`, `fieldreps`.`longer` AS `fieldreps.longer`, `fieldreps`.`commitment` AS `fieldreps.commitment`, `fieldreps`.`travel_metro` AS `fieldreps.travel_metro`, `fieldreps`.`travel_states` AS `fieldreps.travel_states`, `fieldreps`.`big_employee` AS `fieldreps.big_employee`, `fieldreps`.`employed` AS `fieldreps.employed`, `fieldreps`.`retail` AS `fieldreps.retail`, `fieldreps`.`status` AS `fieldreps.status`, `fieldreps`.`start` AS `fieldreps.start`, `fieldreps`.`sales` AS `fieldreps.sales`, `fieldreps`.`study` AS `fieldreps.study`, `fieldreps`.`relevant` AS `fieldreps.relevant`, `fieldreps`.`experience` AS `fieldreps.experience`, `fieldreps`.`claims` AS `fieldreps.claims`, `fieldreps`.`education` AS `fieldreps.education`, `fieldreps`.`degree_details` AS `fieldreps.degree_details`, `fieldreps`.`degree_institution` AS `fieldreps.degree_institution`, `fieldreps`.`other_training` AS `fieldreps.other_training`, `fieldreps`.`jobs` AS `fieldreps.jobs`, `fieldreps`.`current_training` AS `fieldreps.current_training`, `fieldreps`.`interested` AS `fieldreps.interested`, `fieldreps`.`achievements` AS `fieldreps.achievements`, `fieldreps`.`passions` AS `fieldreps.passions`, `fieldreps`.`ambitions` AS `fieldreps.ambitions`, `fieldreps`.`max_travel_time` AS `fieldreps.max_travel_time`, `fieldreps`.`creation_time` AS `fieldreps.creation_time`, `fieldreps`.`resume` AS `fieldreps.resume`, `users`.`user_id` AS `users.user_id`, `users`.`email` AS `users.email`, `users`.`name` AS `users.name`, `users`.`password` AS `users.password`, `users`.`given_name` AS `users.given_name`, `users`.`title` AS `users.title`, `users`.`nationality` AS `users.nationality`, `availabilities`.`availability_id` AS `availabilities.availability_id`, `availabilities`.`fieldrep_id` AS `availabilities.fieldrep_id`, `availabilities`.`mon_start` AS `availabilities.mon_start`, `availabilities`.`mon_end` AS `availabilities.mon_end`, `availabilities`.`tue_start` AS `availabilities.tue_start`, `availabilities`.`tue_end` AS `availabilities.tue_end`, `availabilities`.`wed_start` AS `availabilities.wed_start`, `availabilities`.`wed_end` AS `availabilities.wed_end`, `availabilities`.`thur_start` AS `availabilities.thur_start`, `availabilities`.`thur_end` AS `availabilities.thur_end`, `availabilities`.`fri_start` AS `availabilities.fri_start`, `availabilities`.`fri_end` AS `availabilities.fri_end`, `availabilities`.`sat_start` AS `availabilities.sat_start`, `availabilities`.`sat_end` AS `availabilities.sat_end`, `availabilities`.`sun_start` AS `availabilities.sun_start`, `availabilities`.`sun_end` AS `availabilities.sun_end` FROM `fieldreps` AS `fieldreps` 
LEFT JOIN `users` ON (`fieldreps`.`user_id` = `users`.`user_id`) LEFT JOIN `availabilities` ON (`fieldreps`.`availability_id` = `availabilities`.`availability_id`)

I now get the result I want:

[0] => Array
    (
        [fieldreps.user_id] => 1f01f4c2-43fd-550d-a53d-1f191786ebad
        [fieldreps.availability_id] => e31b0773-ecba-41d1-8ebb-7ac718496456
        [fieldreps.car] => Yes
        [fieldreps.authorized_worker] => Yes
        [fieldreps.restrictions] => Has Restrictions: No 
        [fieldreps.night] => Yes
        [fieldreps.day] => Yes
        [fieldreps.longer] => Yes
        [users.user_id] => 1f01f4c2-43fd-550d-a53d-1f191786ebad
        [users.email] => dsfsdfsdfsdfsdfs@sdfsdfsdfsdfsd.com
        [users.name] => Jones
        [users.password] =>
        [users.given_name] => Fred
        [users.title] => Miss
        [users.nationality] => 
        [availabilities.availability_id] => e31b0773-ecba-41d1-8ebb-7ac718496456
        [availabilities.fieldrep_id] => 1f01f4c2-43fd-550d-a53d-1f191786ebad
        [availabilities.mon_start] => 540
        [availabilities.mon_end] => 1020
        [availabilities.tue_start] => 540
        [availabilities.tue_end] => 1020
        [availabilities.wed_start] => 540
        [availabilities.wed_end] => 1020
        [availabilities.thur_start] => 540
        [availabilities.thur_end] => 1020
        [availabilities.fri_start] => 540
        [availabilities.fri_end] => 1020
        [availabilities.sat_start] => 
        [availabilities.sat_end] => 
        [availabilities.sun_start] => 
        [availabilities.sun_end] => 
    )
[1] => Array
    (
        [fieldreps.user_id] => 812c3a9f-d7d8-565a-a886-1b182753dd41
        [fieldreps.availability_id] => 
        [fieldreps.car] => 1
        [fieldreps.authorized_worker] => 1
        [fieldreps.restrictions] => 
        [fieldreps.night] => 1
        [fieldreps.day] => 1
        [fieldreps.longer] => 1
        [users.user_id] => 812c3a9f-d7d8-565a-a886-1b182753dd41
        [users.email] => sdfsdfsdfsdfsdf@sdfsdfsdfsdf.com
        [users.name] => Smith
        [users.password] => 
        [users.given_name] => Jill 
        [users.title] => 
        [users.nationality] => 
        [availabilities.availability_id] => 
        [availabilities.fieldrep_id] => 
        [availabilities.mon_start] => 
        [availabilities.mon_end] => 
        [availabilities.tue_start] => 
        [availabilities.tue_end] => 
        [availabilities.wed_start] => 
        [availabilities.wed_end] => 
        [availabilities.thur_start] => 
        [availabilities.thur_end] => 
        [availabilities.fri_start] => 
        [availabilities.fri_end] => 
        [availabilities.sat_start] => 
        [availabilities.sat_end] => 
        [availabilities.sun_start] => 
        [availabilities.sun_end] => 

Notice that the LEFT JOIN on the Users table works fine in both scenarios. I also tried adding the newline before the second LEFT JOIN, instead of the first. Same unwanted result. The only thing that I can find to fix it is placing a newline in front of the first LEFT JOIN. The queries that are built by QueryBuilder and sent to MySQL are always long, single-line, minimum whitespace strings…no newlines! This is the first time I have had this issue. I just can’t believe there would be a requirement to place a newline before the first LEFT JOIN.

My question boils down to these points:

  1. Is this supposed be happening this way? (Whitespace effecting the query result)
  2. What is the best way to go about getting the result I want.

I am not an SQL expert, otherwise I would probably not need to ask this question. I am sure there is something I am overlooking.

Thank you,

Jonathan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:21:43+00:00Added an answer on May 27, 2026 at 8:21 pm

    My issue was right in front of me like I thought:

    Indices

    I had inadvertently created two indices on availabilities.fieldrep_id, and the indices on the rest of the schema were, shoddy-at best.

    I used EXPLAIN which indicated it was not using an index for 2 of the three joins. I cleaned up my indices and now it works great, everytime.

    Also, I think I figured out why the newline would change the query. If I ran the query over and over I would see it switch between the examples given, regardless of adding the newline or not. I am assuming that MySQL has some caching for repeat queries. I bet that the newline was enough to trigger it to ignore the cached version, hence it would sometimes give me the desired result.

    Regardless, the issue was with indices. Everything else was just a symptom.

    Maybe this will help someone save a bit of time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been having an issue getting .getScript to work in some odd cases. For
I'm having an odd issue. I have a simple web page, and for some
I have an odd need to open two separate instances of excel and having
I'm having an odd issue with Expression Blend 4. I've been using Blend 4
I seem to be having an odd issue w/ the ApplicationDeployment.CheckForUpdateAsync Method. I have
I'm having an odd issue with CALayer drawing for the iPhone. I have a
I'm having a really odd issue and maybe one of you can shed some
I've been having an issue which is extremely odd to me. The graphic I'm
I'm having a particularly odd issue when developing Chrome extensions using jQuery. I have
I have having a very odd issue when utilizing this UIAlertView. When viewing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.