All I want to ask is
What can you think of in your WILDEST imagination that explains a query that returns results 1 out of several times?
The same exact query (from a mysql prompt) I execute (by pressing the UP key) repeatedly sometimes returns results other times it's an empty result set.
The data is not being rebuild and updated in the background. In fact there is a cron job that updates it every half hour, I've taken that out. There is no other process changing the data.
What in the Universe is going on?
The query is simple. SELECT some fields FROM a few different tables WHERE cartesian joins. (tried LEFT JOINS too).
I use a Stored Function that converts an ID between two format to join a couple of those tables (I had a thread about this function a while back if you remember)
Shoot whatever ideas you have at me. At this point what I know of simple logic is going out the window and I'm ready to smash the computer with a rock.
I envy cavemen
Thanks to anyone who can make me sane again,
Dan
2 1707
I think I found a MySQL bug.
I'm going to create a sample DB with sample Tables and create a Stored Function.
I think the stored function caches the last value returned and returns it even if given a different input but only when used in a LEFT JOIN. Function works fine if you just do a SELECT with it.
Will keep you updated...
Dan
Hey Guys,
If anybody has a test MySQL server handy, could you look over this bug report. I'll submit it to MySQL bug if you guys confirm it on your end too.
Thanks alot. -
-
/**
-
-
Desc: Example Schema, Data and Query that illustrate a possible MySQL bug involving use Stored Function in a LEFT JOIN.
-
-
Created: 10/05/2009
-
Author: Dan M (dlite922)
-
Version: mysql Ver 14.12 Distrib 5.0.45, for redhat-linux-gnu (x86_64) using readline 5.0
-
Repeatability: Always
-
-
/*
-
-
/** SCHEMA **/
-
drop table IF EXISTS image;
-
drop table IF EXISTS event_image;
-
drop table IF EXISTS event;
-
-
Create table event (
-
event_id Int NOT NULL AUTO_INCREMENT,
-
preconverted_id Varchar(5) NOT NULL,
-
name Varchar(20) NOT NULL,
-
UNIQUE (event_id),
-
Primary Key (event_id)) ENGINE = MyISAM;
-
-
Create table event_image (
-
postconverted_id Int NOT NULL,
-
image_id Int,
-
UNIQUE (postconverted_id),
-
Primary Key (postconverted_id)) ENGINE = MyISAM;
-
-
Create table image (
-
image_id Int NOT NULL AUTO_INCREMENT,
-
image_name Varchar(20) NOT NULL,
-
image_type Varchar(4) NOT NULL,
-
UNIQUE (image_id),
-
Primary Key (image_id)) ENGINE = MyISAM;
-
-
-
-
-
/** STORED FUNCTION TO CONVERT IDs **/
-
DELIMITER $$
-
DROP FUNCTION IF EXISTS ConvertID$$
-
CREATE FUNCTION ConvertID(preconverted_id VARCHAR(5)) RETURNS INT
-
DETERMINISTIC
-
BEGIN
-
DECLARE catText CHAR(1);
-
DECLARE catNum INT;
-
DECLARE series CHAR(4);
-
DECLARE FinalID INT;
-
-
SET catText = SUBSTRING(preconverted_id FROM 1 FOR 1);
-
SET series = SUBSTRING(preconverted_id FROM 2 FOR 5);
-
-
IF(catText = 'A') THEN
-
SET catNum = 1;
-
ELSEIF(catText = 'B') THEN
-
SET catNum = 2;
-
ELSEIF(catText = 'C') THEN
-
SET catNum = 3;
-
END IF;
-
-
SET FinalID = (catNum << 26 | series);
-
RETURN FinalID;
-
END $$
-
DELIMITER ;
-
-
-
-
-
/** SAMPLE DATA **/
-
INSERT INTO event VALUES (1,'A1234','Bar'),(2,'B5678','Foo'),(3,'C9011','Baz');
-
INSERT INTO event_image VALUES (67110098,55),(134223406,97),(201335603,42);
-
INSERT INTO image VALUES (55,'Bar_and_friends','jpg'),(97,'FoorAreYou','gif'),(42,'BazFishing','png');
-
-
-
-
-
-
/** QUERY THAT EXPOSES BUG **/
-
/** PLEASE OBSERVE: covertedColumn. All fields have the converted of the last ID (that of 'Baz'). **/
-
SELECT
-
e.event_id,
-
e.preconverted_id,
-
e.name,
-
ConvertID(e.preconverted_id) AS convertedColumn,
-
ei.postconverted_id,
-
ei.image_id,
-
i.image_id,
-
i.image_name,
-
i.image_type
-
FROM
-
event AS e LEFT JOIN event_image AS ei ON ConvertID(e.preconverted_id) = ei.postconverted_id
-
LEFT JOIN image AS i ON ei.image_id = i.image_id;
-
-
-
/** If you don't believe my function is working properly checkout these results **/
-
SELECT e.event_id, e.name, ConvertID(e.preconverted_id) FROM event AS e;
-
-
// OR SIMPLY:
-
SELECT ConvertID('A1234');
-
SELECT ConvertID('B5678');
-
SELECT ConvertID('C9011');
-
-
-
// END OF FILE
-
-
I've tried with and without the DETERMINISTIC flag on the function.
Please let me know if you see something odd. I often make silly mistakes.
Thanks again,
Dan
Sign in to post your reply or Sign up for a free account.
Similar topics
by: RH |
last post by:
<SELECT name="txtServices" size="3" multiple>
<OPTION value="Massage">Massage</OPTION>
<OPTION value="Facials">Facials</OPTION>
<OPTION value="Wet & Dry Body Treatments">Wet & Dry Body...
|
by: Tony |
last post by:
Question...
I am preparing a presentation on Oracle for my Senior Capstone class
at Colorado State University.
Does ANYONE know Oracle's Mission Statement or have a link pointing to
it...
|
by: longhorntx |
last post by:
I have a table with following values
City STATE COLOR REGION
city1 Texas White SW
city2 Texas Gray SW
city3 Texas Gray SW
city4 Nevada Gray PAC
c5 Texas Yellow SW
c6 Florida Yellow SE...
|
by: Robert Brown |
last post by:
suppose I have the following table:
CREATE TABLE (int level, color varchar, length int, width int, height
int)
It has the following rows
1, "RED", 8, 10, 12
2, NULL, NULL, NULL, 20...
|
by: John |
last post by:
Is there a way to code the button that's available in the query
window--microsoft excel icon that exports to excel. I know
transferspreadsheet will do this---but I want the query, which is in a...
|
by: Alan |
last post by:
I'm having a bit of difficulty getting the results I need from our database.
In a nutshell I'm trying to work out trends in what people buy next. So, for
example, I'm trying to run a query that...
|
by: Photo |
last post by:
Hello everyone this is my first post so as you could guess I need some help. Here is my situation, I have 2 tables, one caled personnel and one called DET_Dates, DET_Dates is linked to Personnel on...
|
by: lorirobn |
last post by:
Hi,
I have a report displaying items that are missing from a room. I
created 2 queries, the first getting the items IN the room, and the
second being an "unmatched" query that references the...
|
by: zion4ever |
last post by:
Hello good people,
Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |