EllisLab text mark
Advanced Search
     
Active Record query cache eating queries.  Looks like BUG
Posted: 16 November 2012 09:33 PM   [ Ignore ]
Joined: 2012-08-29
16 posts

Query cache is eating complex sub queries in select().

Here is DB info.

tableA

DROP TABLE IF EXISTS `tablea`;
CREATE TABLE `tablea` (
  `
a_numberint(11) DEFAULT NULL,
  `
b_numbervarchar(255) DEFAULT NULL,
  `
c_numbervarchar(255) DEFAULT NULL,
  `
b_statusvarchar(255) DEFAULT NULL
ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `tableaVALUES ('11111''F-99999''1-PPPPP''Open');
INSERT INTO `tableaVALUES ('22222''F-99999''1-PPPPP''Closed');
INSERT INTO `tableaVALUES ('33333''F-99999''2-PPPPP''Closed');
INSERT INTO `tableaVALUES ('44444''F-99999''2-PPPPP''Closed');
INSERT INTO `tableaVALUES ('55555''F-88888''1-PPPPP''Open');
INSERT INTO `tableaVALUES (nullnull'3-PPPPP'null); 

tableB

DROP TABLE IF EXISTS `tableb`;
CREATE TABLE `tableb` (
  `
c_numbervarchar(255) DEFAULT NULL
ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `tablebVALUES ('1-PPPPP');
INSERT INTO `tablebVALUES ('2-PPPPP');
INSERT INTO `tablebVALUES ('3-PPPPP'); 

Here is the query in CI

$this->db->start_cache();
$this->db->select("
tableb.c_number,
(SELECT
CASE
WHEN GROUP_CONCAT(CONCAT(tablea.a_number,' - ',tablea.b_number),CONCAT(' (',tablea.b_status,') ')) IS NULL
THEN 'NO A_NUMBER'
ELSE GROUP_CONCAT(CONCAT(tablea.a_number,' - ',tablea.b_number),CONCAT(' (',tablea.b_status,') '))
END
FROM tablea
WHERE tablea.c_number = tableb.c_number)
"
,FALSE);
$this->db->from('tableb');
$this->db->stop_cache();
$this->db->get(); 

This is what is getting sent to MySQL

SELECT tableb.c_number
(
SELECT
 
CASE
 
WHEN GROUP_CONCAT(CONCAT(tablea.a_number' - 'tablea.b_number), CONCAT(' ('tablea.b_status') ')) IS NULL
 THEN 
'NO A_NUMBER'
 
ELSE GROUP_CONCAT(CONCAT(tablea.a_number') '))
 
END
FROM 
(`tableb`) 

 

 
Posted: 16 November 2012 10:45 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2009-04-15
453 posts

what is it exactly you are trying to point out?

 Signature 

Code By Jeff

Mahana Messaging Library

Problem with your query? Did you run

$this->db->last_query(); 

before you came to the forums for help?

 
Posted: 16 November 2012 11:13 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-08-29
16 posts
jmadsen - 16 November 2012 10:45 PM

what is it exactly you are trying to point out?

Sorry…your blindness must be affecting you.

Here is the query as I have it in CI.

$this->db->start_cache();
$this->db->select("
tableb.c_number,
(SELECT
CASE
WHEN GROUP_CONCAT(CONCAT(tablea.a_number,' - ',tablea.b_number),CONCAT(' (',tablea.b_status,') ')) IS NULL
THEN 'NO A_NUMBER'
ELSE GROUP_CONCAT(CONCAT(tablea.a_number,' - ',tablea.b_number),CONCAT(' (',tablea.b_status,') '))
END
FROM tablea
WHERE tablea.c_number = tableb.c_number)
"
,FALSE);
$this->db->from('tableb');
$this->db->stop_cache();
$this->db->get(); 

Here is the query that CI is sending to mysql

SELECT tableb.c_number
(
SELECT
 
CASE
 
WHEN GROUP_CONCAT(CONCAT(tablea.a_number' - 'tablea.b_number), CONCAT(' ('tablea.b_status') ')) IS NULL
 THEN 
'NO A_NUMBER'
 
ELSE GROUP_CONCAT(CONCAT(tablea.a_number') '))
 
END
FROM 
(`tableb`) 

If I don’t use query cache the query is fine. 

Really?  You can’t see what’s in plain English there…did you even try to re-create the issue before replying?

 

 
Posted: 16 November 2012 11:18 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
3801 posts

Your answer is in the user guide.  Didn’t you read it before posting?

This has also been asked and answered many times on the forums.  Did you try searching before posting?

We can play that game too, but it won’t help you get very far now will it…

 Signature 
 
Posted: 16 November 2012 11:42 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2009-04-15
453 posts
mikerh - 16 November 2012 11:13 PM

did you even try to re-create the issue before replying?

No, I didn’t. I’m here as a volunteer.

I have no interest in spending time trying to recreate an issue that the poster can’t even explain clearly. Obviously there is some difference in your query - tell us what it is we should be looking for when you report the bug.

And after acting like such a complete dickhead, don’t expect anyone in these forums to make much effort helping you in the future.

 Signature 

Code By Jeff

Mahana Messaging Library

Problem with your query? Did you run

$this->db->last_query(); 

before you came to the forums for help?

 
Posted: 16 November 2012 11:55 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2012-08-29
16 posts

Fixed

https://github.com/EllisLab/CodeIgniter/issues/2004

https://github.com/EllisLab/CodeIgniter/commit/eae17d19fa32847f2b5a0a1b195f912dc8386ecf

Nice turnaround.

Thanks to those who actually looked into the issue…good thing it was “in the user guide” rolleyes