How to optimization this MYSQL query? - mysql

I have two table the structure are given bellow, those table have lots of data but can't change the table stucture
Table "postsale"
CREATE TABLE IF NOT EXISTS `postsale` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`group_id` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`season` varchar(25) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`sale_no` int(5) NOT NULL,
`auction_date` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`season_time` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`lot_no` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`invoice_no` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`origin` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`tea_type` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`sub_tea_type` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`category` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`mark` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`grade` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`no_of_packages` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`gross_wt` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`net_wt` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`auction_valuation` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`lsp_sp` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`package_type` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`package_no` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`quantity` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`auctioneer` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`auction_price` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`buyer` text CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`area` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`broker_code` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`csv` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`session` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=29623 ;
and Table finalesale
CREATE TABLE IF NOT EXISTS `finalsale` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`group_id` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`season` varchar(25) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`sale_no` int(5) NOT NULL,
`auction_date` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`season_time` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`lot_no` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`invoice_no` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`origin` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`tea_type` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`sub_tea_type` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`category` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`mark` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`grade` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`no_of_packages` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`gross_wt` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`net_wt` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`auction_valuation` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`lsp_sp` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`package_type` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`package_no` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`quantity` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`auctioneer` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`auction_price` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`buyer` text CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`area` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`broker_code` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`csv` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`session` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=41365 ;
based on the above two table, the execution time of this query is huge so, I need to optimized the following query
UPDATE `finalsale`,`postsale`
SET
`finalsale`.`auction_price`=`postsale`.`auction_price`,
`finalsale`.`csv`=`postsale`.`csv`,
`finalsale`.`session`=`postsale`.`session`
WHERE `finalsale`.`lot_no`=`postsale`.`lot_no`
AND `finalsale`.`group_id`=`postsale`.`group_id`
AND `finalsale`.`group_id`='201217CLGuwahatiJT'
Please help

You will get a serious performance improvement from choosing the correct data types in your table definition.
There are several columns which appear to contain only numerical information, which is better stored in some int column.
Furthermore there are columns for some dates like auction_date that should be transformed to a date - datatype.
Also think about the length of your varchar columns. Most of the time you wont need the 255 characters there.
Have a close look at the Mysql Docu for datatypes.
If you have performance problems afterwards you may think about creating indexes on some columns. But I strongly recommend thinking about this just AFTER you reworked your table definitions!

Assuming it is not possible for you to improve on the schema (which as has been mentioned in the OP comments is rather... bloated), you probably would get a significant performance boost for this specific query by adding an index on lot_no and group_id on each of the tables.
Since you're using InnoDB, you might consider using a foreign key constraint (this also covers indexes), although it depends on the semantics & lifecycle of the tables, which I don't know about.

Add the following indexes:
Single column:
finalsale: (`group_id`)
Multi-column:
postsale: (`group_id, lot_no`)
These indexes allow MySQL to first limit the result set by applying the constant in the WHERE clause to the finalsale table, and then, with that minimal result set, perform a join to the postsale table, fully utilizing the index.

Related

MySQL 1366 incorrect integer value

I am trying to import a csv file into a MySQL DB.
Said csv file is from a select * from the same table
LOAD DATA INFILE 'C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/import.csv'
INTO TABLE fisc_hist_header
character set utf8
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\n'
(-- a whole lot of fields ...)
SET `CREATED_DATE`=STR_TO_DATE( #yourdatecolumn, '%d/%m/%Y %H:%i:%s' )
The file starts with
545752715002093599;3;1;503955117000124560;28/11/2019 14:38:51;0 -- all the other fields
What I get is
After searching here, all results are for
Incorrect integer value: ''
What is different and strange to me is that for me, it gets the value but does not inputs it as an integer ?
EDIT : As asked here is the create table statement:
CREATE TABLE `fisc_hist_header` (
`fiscal_idx` bigint(20) NOT NULL AUTO_INCREMENT,
`invc_sid` bigint(20) NOT NULL,
`sbs_no` int(11) NOT NULL,
`store_no` int(5) NOT NULL,
`workstation_id` bigint(20) NOT NULL,
`created_date` datetime NOT NULL,
`invc_type` int(11) NOT NULL,
`cashier_name` varchar(8) COLLATE utf8_bin DEFAULT NULL,
`associate_name` varchar(8) COLLATE utf8_bin DEFAULT NULL,
`store_code` varchar(5) COLLATE utf8_bin DEFAULT NULL,
`store_name` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_address1` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_address2` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_address3` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_address4` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_address5` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_address6` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_zip` varchar(10) COLLATE utf8_bin DEFAULT NULL,
`customer_sid` bigint(20) DEFAULT NULL,
`customer_title` varchar(15) COLLATE utf8_bin DEFAULT NULL,
`customer_last_name` varchar(30) COLLATE utf8_bin DEFAULT NULL,
`customer_first_name` varchar(30) COLLATE utf8_bin DEFAULT NULL,
`customer_address1` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`customer_address2` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`customer_address3` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`customer_address4` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`customer_zip_code` varchar(10) COLLATE utf8_bin DEFAULT NULL,
`customer_country` varchar(35) COLLATE utf8_bin DEFAULT NULL,
`customer_phone` varchar(30) COLLATE utf8_bin DEFAULT NULL,
`customer_email` varchar(60) COLLATE utf8_bin DEFAULT NULL,
`item_count` int(5) NOT NULL,
`grand_total_receipt` decimal(10,0) NOT NULL,
`prism_version` varchar(19) COLLATE utf8_bin DEFAULT NULL,
`plugin_version` varchar(19) COLLATE utf8_bin DEFAULT NULL,
`flag_first_record` char(1) COLLATE utf8_bin DEFAULT NULL,
`signature_key` varchar(500) COLLATE utf8_bin DEFAULT NULL,
`signature` varchar(500) COLLATE utf8_bin DEFAULT NULL,
`signature_previous` varchar(500) COLLATE utf8_bin DEFAULT NULL,
`signature_short` varchar(10) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`fiscal_idx`),
UNIQUE KEY `un_fhh` (`invc_sid`)
) ENGINE=InnoDB AUTO_INCREMENT=364 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
As per the documentation for integer values, the maximum value for an unsigned integer which can be held in an INT column is 4294967295. For a standard signed integer it's 2147483647.
Your number 545752715002093599 is larger than both of these. You'll need to declare the target column as BIGINT in your fisc_hist_header table - the max value for a signed integer in this column type is 9223372036854775807.
These restrictions exist because of the number of bytes used by MySQL to store each value in the database. If you know you won't need to store values above a certain limit, you can use a smaller integer type in order to save disk space and memory.

mysql: (pdo) continue at last position without using OFFSET

I wish to retrieve around 200 million profiles using PDO.
It is a partitioned table, so it does not have a primary key, it's sorted with INNODBs internal primary key.
I need to retrieve the data in internal sort order for performance, so using SORT BY some_id and to continue from there would not work for performance reasons.
Using LIMIT OFFSET would not work at all, OFFSET 100 million or more would take ages, the RAM is by far not enough to take all the terrabyte of table data into cache.
I would need something that fetches a chunk of rows, remembers the internal position and continues with next call.
Update
I was digging a bit and the problem seems familiar, it was solved in Oracle by having ROWID and ROWNUM which refer to the internal id.
It seems we have such an id in innodb as well but it's not queryable ?!
That sounds like a significant disadvantage of mysql for performant query.
Table def:
CREATE TABLE `members` (
`id` int(11) NOT NULL DEFAULT 0,
`intern_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`first_name` varchar(48) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`last_name` varchar(48) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`middle_name` varchar(48) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`l` varchar(196) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`i` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`ex` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`country_code` varchar(4) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`country_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`state_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`city_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`edu` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`nc` smallint(6) DEFAULT NULL,
`nj` smallint(6) DEFAULT NULL,
`jt` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`cn` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`email_address` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`fpe` tinyint(4) DEFAULT NULL COMMENT '1/0',
`pbu` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`cii` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`unmatched_facts` varchar(2048) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`dt_snapshot` datetime DEFAULT NULL,
`change_small` tinyint(4) DEFAULT NULL,
`change_significant` tinyint(4) DEFAULT NULL,
`jta` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`cna` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`cnia` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`ut_created` int(11) DEFAULT NULL ,
`reserve_int_2` int(11) DEFAULT NULL,
`reserve_vc1` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`reserve_vc2` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`reserve_vc_3` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
KEY `id` (`id`),
KEY `intern_id` (`intern_id`),
KEY `state_name` (`state_name`),
KEY `city_name` (`city_name`),
KEY `i` (`i`),
KEY `country_name` (`country_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
PARTITION BY KEY (`country_name`)
PARTITIONS 30

mySQL: Illegal mix of collations (utf8mb4_bin,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='

I'm trying to figure out why my CMS is giving me an error, but SQLFiddle and phpMyAdmin both run the query fine. Here is the fiddle:
http://sqlfiddle.com/#!9/cadc53/2
So the sample data:
CREATE TABLE IF NOT EXISTS `glinks_Sales` (
`TransactionID` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
`Billing_Name` char(255) COLLATE utf8mb4_bin DEFAULT NULL,
`Billing_Street` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Billing_City` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Billing_State` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Billing_PostCode` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Billing_Country` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Shipping_Name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Shipping_Street` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Shipping_City` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Shipping_State` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Shipping_PostCode` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Shipping_Country` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Been_Dispatched` int(11) NOT NULL,
`Postcode_Check_Status` varchar(10) COLLATE utf8mb4_bin DEFAULT NULL,
`Billing_Street_2` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
`Shipping_Street_2` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
`Items_In_Order` longtext COLLATE utf8mb4_bin,
`Email` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
`unique_id` int(11) NOT NULL,
`Order_Date` bigint(20) DEFAULT NULL,
`Method` char(10) COLLATE utf8mb4_bin DEFAULT NULL,
`Currency` char(3) COLLATE utf8mb4_bin DEFAULT NULL,
`Shipping_Amount` float DEFAULT NULL,
`Language` varchar(5) COLLATE utf8mb4_bin DEFAULT NULL,
`Cancelled` int(11) DEFAULT NULL,
`TrackingNumber` varchar(200) COLLATE utf8mb4_bin DEFAULT NULL,
`PostageCompany` varchar(200) COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
ALTER TABLE `glinks_Sales`
ADD PRIMARY KEY (`unique_id`);
INSERT INTO `glinks_Sales` (`TransactionID`, `Billing_Name`, `Billing_Street`, `Billing_City`, `Billing_State`, `Billing_PostCode`, `Billing_Country`, `Shipping_Name`, `Shipping_Street`, `Shipping_City`, `Shipping_State`, `Shipping_PostCode`, `Shipping_Country`, `Been_Dispatched`, `Postcode_Check_Status`, `Billing_Street_2`, `Shipping_Street_2`, `Items_In_Order`, `Email`, `unique_id`, `Order_Date`, `Method`, `Currency`, `Shipping_Amount`, `Language`, `Cancelled`, `TrackingNumber`, `PostageCompany`) VALUES ('8LL79654AS664260H', 'Andyííííééé Íóé', 'xxxx', 'Rudgwick', 'West Sussex', 'xxx', 'GB', 'Andyííííééé Íóé ', 'foo', 'x', 'West Sussex', 'x', 'GB', 1488558170, '1', '', '', 'test', 'ss#gmail.com', 15, 1488472336, 'PayPal', '', 10, 'en', NULL, 'foo', 'royal mail');
Then a sample query to grab
SELECT * FROM glinks_Sales WHERE (Shipping_Name = "Andyííííééé Íóé" OR Email = "Íóé" OR unique_id = "Íóé" OR TrackingNumber = "Íóé" OR PostageCompany = "Íóé")
That runs just fine. However, my Perl script that accesses the database does:
SELECT * FROM glinks_Sales WHERE (TransactionID = ?) ORDER BY Order_Date ASC'
...and it spits out the error:
Illegal mix of collations (utf8mb4_bin,IMPLICIT) and
(utf8_general_ci,COERCIBLE) for operation '='
I'm confused as to where it would be getting utf8_general_ci from? I must be missing something stupid, but I can't see it. Hopefully a fresh pair of eyes will help!
Thanks for any suggestions!
Collation mixes can be a pain. Try to SET collation_connection = 'utf8mb4_bin' before the query:
SET collation_connection = 'utf8mb4_bin';
SELECT * FROM glinks_Sales WHERE (TransactionID = ?) ORDER BY Order_Date ASC';
This sets the collation for the connection, before you run your query.
If that do not work, check other possible collation settings for database, server or connection. You find some hints here: https://stackoverflow.com/a/37298732/1363190

error in creating mysql table

I get an error when i execute this script:
create table orbeon_form_definition_attach (
created timestamp(6),
last_modified_time timestamp(6),
last_modified_by varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
app varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
form varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
form_version int not null,
deleted char(1) COLLATE utf8_bin NOT NULL,
file_name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
file_content longblob
) engine = InnoDB;
The error is : Error Code: 1064. You have an error in your SQL syntax check the manual that corresponds to your MySQL server version for the right syntax to use near (6), last_modified_time timestamp(6), last_modified_by varchar(255) at line 2 0.000 sec
any idea how to solve this??
datetime or timestamp does not have a length
create table orbeon_form_definition_attach
(
created datetime,
last_modified_time datetime,
last_modified_by varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
app varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
form varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
form_version int not null,
deleted char(1) COLLATE utf8_bin NOT NULL,
file_name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin,
file_content longblob
) engine = InnoDB;

Same MySQL Query Returning Different Results on Same Server

I am running the following query. Sometimes it returns around 100 records, as expected, other times is returns only one record with NULL for all of the values of the joined fields. Also, explain returns a different result almost everytime.
Here is the query:
EXPLAIN
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`,
`tasks`.`task_id` AS `tasks.task_id`,
`tasks`.`recurrence_id` AS `tasks.recurrence_id`,
`tasks`.`parent_id` AS `tasks.parent_id`,
`tasks`.`user_id` AS `tasks.user_id`,
`tasks`.`campaign_id` AS `tasks.campaign_id`,
`tasks`.`location_id` AS `tasks.location_id`,
`tasks`.`title` AS `tasks.title`,
`tasks`.`description` AS `tasks.description`,
`tasks`.`earliest_start` AS `tasks.earliest_start`,
`tasks`.`deadline` AS `tasks.deadline`,
`tasks`.`km_estimate` AS `tasks.km_estimate`,
`tasks`.`estimate` AS `tasks.estimate`,
`datapoints`.`datapoint_id` AS `datapoints.datapoint_id`,
`datapoints`.`task_id` AS `datapoints.task_id`,
`datapoints`.`datatype_id` AS `datapoints.datatype_id`,
`datapoints`.`value` AS `datapoints.value`,
`datapoints`.`product_id` AS `datapoints.product_id`,
`datapoints`.`recorded` AS `datapoints.recorded`,
`datatypes`.`datatype_id` AS `datatypes.datatype_id`,
`datatypes`.`datatype_template_id` AS `datatypes.datatype_template_id`,
`datatypes`.`client_id` AS `datatypes.client_id`,
`datatypes`.`name` AS `datatypes.name`,
`datatypes`.`description` AS `datatypes.description`,
`datatypes`.`options` AS `datatypes.options`,
`locations`.`location_id` AS `locations.location_id`,
`locations`.`retailer_group_id` AS `locations.retailer_group_id`,
`locations`.`latitude` AS `locations.latitude`,
`locations`.`longitude` AS `locations.longitude`,
`locations`.`name` AS `locations.name`,
`locations`.`address` AS `locations.address`,
`locations`.`city` AS `locations.city`,
`locations`.`state` AS `locations.state`,
`locations`.`postal` AS `locations.postal`,
`locations`.`phone` AS `locations.phone`,
`locations`.`suburb` AS `locations.suburb`,
`locations`.`country` AS `locations.country`,
`locations`.`region` AS `locations.region`,
`locations`.`coverage` AS `locations.coverage`,
`locations`.`store_number` AS `locations.store_number`,
`locations`.`store_type` AS `locations.store_type`
FROM `fieldreps` AS `fieldreps`
LEFT JOIN `users` ON (`fieldreps`.`user_id` = `users`.`user_id`)
LEFT JOIN `tasks` ON (`fieldreps`.`user_id` = `tasks`.`user_id`)
LEFT JOIN `datapoints` ON (`tasks`.`task_id` = `datapoints`.`task_id`)
LEFT JOIN `datatypes` ON (`datapoints`.`datatype_id` = `datatypes`.`datatype_id`)
LEFT JOIN `locations` ON (`tasks`.`location_id` = `locations`.`location_id`)
WHERE `fieldreps`.`user_id` LIKE '5f5dc29c-832e-5646-9dc2-46d774bfb1ec'
I am running the query in phpMyAdmin. Database is hosted on xeround.com(Could it be a bug in their configuration?)
I am stumped. I am not sure where to go from here.
Thanks in advance!
UPDATE:
Here is the dump from phpMyAdmin:
-- phpMyAdmin SQL Dump
-- version 3.4.3.2
-- http://www.phpmyadmin.net
--
-- Generation Time: Jan 07, 2012 at 08:20 PM
-- Server version: 5.1.42
-- PHP Version: 5.3.1
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `big_development`
--
-- --------------------------------------------------------
--
-- Table structure for table `datapoints`
--
CREATE TABLE IF NOT EXISTS `datapoints` (
`datapoint_id` varchar(36) COLLATE utf8_bin NOT NULL,
`task_id` varchar(36) COLLATE utf8_bin NOT NULL,
`datatype_id` varchar(36) COLLATE utf8_bin NOT NULL,
`value` text COLLATE utf8_bin,
`product_id` varchar(36) COLLATE utf8_bin DEFAULT NULL,
`recorded` text COLLATE utf8_bin,
PRIMARY KEY (`datapoint_id`),
KEY `task_id` (`task_id`),
KEY `datatype_id` (`datatype_id`),
KEY `product_id` (`product_id`)
) ENGINE=Xeround DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-- --------------------------------------------------------
--
-- Table structure for table `datatypes`
--
CREATE TABLE IF NOT EXISTS `datatypes` (
`datatype_id` varchar(36) COLLATE utf8_bin NOT NULL,
`datatype_template_id` varchar(36) COLLATE utf8_bin NOT NULL,
`client_id` varchar(36) COLLATE utf8_bin NOT NULL,
`name` text COLLATE utf8_bin,
`description` text COLLATE utf8_bin,
`options` text COLLATE utf8_bin,
PRIMARY KEY (`datatype_id`),
KEY `datatype_template_id` (`datatype_template_id`),
KEY `client_id` (`client_id`)
) ENGINE=Xeround DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-- --------------------------------------------------------
--
-- Table structure for table `fieldreps`
--
CREATE TABLE IF NOT EXISTS `fieldreps` (
`user_id` varchar(36) COLLATE utf8_bin NOT NULL,
`availability_id` varchar(36) COLLATE utf8_bin NOT NULL,
`applicant_type` text COLLATE utf8_bin NOT NULL,
`license_number` text COLLATE utf8_bin NOT NULL,
`license_exp` text COLLATE utf8_bin,
`license_state` text COLLATE utf8_bin,
`car` text COLLATE utf8_bin NOT NULL,
`authorized_worker` text COLLATE utf8_bin NOT NULL,
`restrictions` text COLLATE utf8_bin NOT NULL,
`night` text COLLATE utf8_bin NOT NULL,
`day` text COLLATE utf8_bin NOT NULL,
`longer` text COLLATE utf8_bin NOT NULL,
`commitment` text COLLATE utf8_bin NOT NULL,
`travel_metro` text COLLATE utf8_bin NOT NULL,
`travel_states` text COLLATE utf8_bin NOT NULL,
`big_employee` text COLLATE utf8_bin NOT NULL,
`employed` text COLLATE utf8_bin NOT NULL,
`retail` text COLLATE utf8_bin NOT NULL,
`status` text COLLATE utf8_bin NOT NULL,
`start` text COLLATE utf8_bin,
`sales` text COLLATE utf8_bin NOT NULL,
`study` text COLLATE utf8_bin NOT NULL,
`relevant` text COLLATE utf8_bin NOT NULL,
`experience` text COLLATE utf8_bin NOT NULL,
`claims` text COLLATE utf8_bin NOT NULL,
`education` text COLLATE utf8_bin NOT NULL,
`degree_details` text COLLATE utf8_bin NOT NULL,
`degree_institution` text COLLATE utf8_bin NOT NULL,
`other_training` text COLLATE utf8_bin NOT NULL,
`jobs` text COLLATE utf8_bin NOT NULL,
`current_training` text COLLATE utf8_bin NOT NULL,
`interested` text COLLATE utf8_bin NOT NULL,
`achievements` text COLLATE utf8_bin NOT NULL,
`passions` text COLLATE utf8_bin NOT NULL,
`ambitions` text COLLATE utf8_bin NOT NULL,
`max_travel_time` text COLLATE utf8_bin NOT NULL,
`creation_time` text COLLATE utf8_bin,
`resume` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`user_id`),
KEY `availability_id` (`availability_id`)
) ENGINE=Xeround DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-- --------------------------------------------------------
--
-- Table structure for table `locations`
--
CREATE TABLE IF NOT EXISTS `locations` (
`location_id` varchar(36) COLLATE utf8_bin NOT NULL,
`retailer_group_id` varchar(36) COLLATE utf8_bin NOT NULL,
`latitude` text COLLATE utf8_bin,
`longitude` text COLLATE utf8_bin,
`name` text COLLATE utf8_bin,
`address` text COLLATE utf8_bin,
`city` text COLLATE utf8_bin,
`state` text COLLATE utf8_bin,
`postal` text COLLATE utf8_bin,
`phone` text COLLATE utf8_bin,
`suburb` text COLLATE utf8_bin,
`country` text COLLATE utf8_bin,
`region` text COLLATE utf8_bin,
`coverage` tinyint(1) DEFAULT NULL,
`store_number` text COLLATE utf8_bin,
`store_type` text COLLATE utf8_bin,
PRIMARY KEY (`location_id`),
KEY `retailer_group_id` (`retailer_group_id`)
) ENGINE=Xeround DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-- --------------------------------------------------------
--
-- Table structure for table `tasks`
--
CREATE TABLE IF NOT EXISTS `tasks` (
`task_id` varchar(36) COLLATE utf8_bin NOT NULL,
`recurrence_id` varchar(36) COLLATE utf8_bin NOT NULL,
`parent_id` varchar(36) COLLATE utf8_bin DEFAULT NULL,
`user_id` varchar(36) COLLATE utf8_bin NOT NULL,
`campaign_id` varchar(36) COLLATE utf8_bin NOT NULL,
`location_id` varchar(36) COLLATE utf8_bin NOT NULL,
`title` text COLLATE utf8_bin,
`description` text COLLATE utf8_bin,
`earliest_start` text COLLATE utf8_bin,
`deadline` text COLLATE utf8_bin,
`km_estimate` text COLLATE utf8_bin,
`estimate` int(11) DEFAULT NULL,
PRIMARY KEY (`task_id`),
KEY `campaign_id` (`campaign_id`),
KEY `location_id` (`location_id`),
KEY `user_id` (`user_id`),
KEY `parent_id` (`parent_id`),
KEY `recurrence_id` (`recurrence_id`)
) ENGINE=Xeround DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`user_id` varchar(36) COLLATE utf8_bin NOT NULL,
`email` varchar(255) COLLATE utf8_bin NOT NULL,
`name` text COLLATE utf8_bin,
`password` varchar(255) COLLATE utf8_bin NOT NULL,
`given_name` text COLLATE utf8_bin,
`title` text COLLATE utf8_bin NOT NULL,
`nationality` text COLLATE utf8_bin,
PRIMARY KEY (`user_id`),
KEY `user_id` (`user_id`)
) ENGINE=Xeround DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
EDIT:
If I remove the join on all tables but user, the query works everytime. However, as soon as I add the join on tasks, it breaks. For example, this query breaks it in the same way as the first query I posted:
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`,
`tasks`.`task_id` AS `tasks.task_id`,
`tasks`.`recurrence_id` AS `tasks.recurrence_id`,
`tasks`.`parent_id` AS `tasks.parent_id`,
`tasks`.`user_id` AS `tasks.user_id`,
`tasks`.`campaign_id` AS `tasks.campaign_id`,
`tasks`.`location_id` AS `tasks.location_id`,
`tasks`.`title` AS `tasks.title`,
`tasks`.`description` AS `tasks.description`,
`tasks`.`earliest_start` AS `tasks.earliest_start`,
`tasks`.`deadline` AS `tasks.deadline`,
`tasks`.`km_estimate` AS `tasks.km_estimate`,
`tasks`.`estimate` AS `tasks.estimate`
FROM `fieldreps` AS `fieldreps`
LEFT JOIN `users` ON (`fieldreps`.`user_id` = `users`.`user_id`)
LEFT JOIN `tasks` ON (`fieldreps`.`user_id` = `tasks`.`user_id`)
WHERE `fieldreps`.`user_id` LIKE '5f5dc29c-832e-5646-9dc2-46d774bfb1ec'
The connection and database collation differed.