If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > 2013 - Lost Connection to MySQL server during query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-27-07, 05:41
gtk gtk is offline
Registered User
 
Join Date: Oct 2004
Location: Paris, FRANCE
Posts: 132
Post 2013 - Lost Connection to MySQL server during query

Hello,

I have MySQL 4.1.12.
I have found a way to reproduce this error with this query:
Code:
SELECT
	tmp.cat AS "cat"
	, CONCAT(tmp.nom, " ", tmp.prenom) AS "learner"
	, CONCAT(tmp.produit, " ", tmp.langue) AS "prod"
	, tmp.langue AS "lang"
	, tmp.division AS "div"
	, tmp.departement AS "dept"
	, tmp.centre AS "center"
	, tmp.tuteur AS "tutor"
	, tmp.date AS "date"
	, DATE_FORMAT(tmp.date, "%M") AS "month"
	, DATE_FORMAT(tmp.date, "%d %b %y") AS "fdate"
	, tmp.statut AS "status"
	, CONCAT(tmp.division, " - ", tmp.langue) AS "div_lang"
	, tmp.cost_center AS "cost_center"
	, tmp.matricule AS "mat"
	, COUNT(DISTINCT IF(tmp.statut = "Present", tmp.sest_id, NULL)) AS "R"
	, COUNT(DISTINCT IF(tmp.statut = "Absent", tmp.sest_id, NULL)) AS "A"
	, COUNT(DISTINCT tmp.sest_id) AS "T"
FROM
	test_data AS tmp
WHERE
	tmp.statut <> ""
GROUP BY
	tmp.langue
	, tmp.tuteur
ORDER BY
	tmp.langue
	, tmp.tuteur
;
from the table enclosed

I'm sure that this bug is known but actually I can't change my version
so I'd like to know if there is a way to override this but avoiding to use
some function in the query or something.
Attached Files
File Type: txt test_data.txt (17.3 KB, 106 views)
Reply With Quote
  #2 (permalink)  
Old 06-28-07, 04:00
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
Argh!

Quote:
COUNT(DISTINCT IF(tmp.statut = "Present", tmp.sest_id, NULL)) AS "R"
, COUNT(DISTINCT IF(tmp.statut = "Absent", tmp.sest_id, NULL)) AS "A"
, COUNT(DISTINCT tmp.sest_id) AS "T"
What is it you're trying to achieve using the table/SQL you have provided?
Reply With Quote
  #3 (permalink)  
Old 06-28-07, 04:10
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
Just to give you a confirmation test, i've loaded up your table in MySQL version 5.0.27 community edition and your query works fine.
Reply With Quote
  #4 (permalink)  
Old 06-28-07, 04:26
gtk gtk is offline
Registered User
 
Join Date: Oct 2004
Location: Paris, FRANCE
Posts: 132
Actually the table provided is a temporary table which my program generates
for the client as detail, so this table should be humain readable.
After that, I use it to perform a kind of ajustable pivot table with MySQL and this
is the query that I put before.
Reply With Quote
  #5 (permalink)  
Old 06-28-07, 04:30
gtk gtk is offline
Registered User
 
Join Date: Oct 2004
Location: Paris, FRANCE
Posts: 132
Thanks aschk for the confirmation.
Can someone try with a version 4.1.x ?
Reply With Quote
  #6 (permalink)  
Old 06-28-07, 06:28
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
You're grouping by
  • tmp.langue
  • tmp.tuteur
but then in the select part you are pulling out the following fields without using any aggregate function.
  • tmp.cat
  • tmp.nom
  • tmp.prenom
  • tmp.produit
  • tmp.langue
  • tmp.langue
  • tmp.division
  • etc ect
Either get rid of the aggregate functions and grouping or apply aggregates to all fields (that you're not grouping by).

Mike
Reply With Quote
  #7 (permalink)  
Old 06-29-07, 03:52
gtk gtk is offline
Registered User
 
Join Date: Oct 2004
Location: Paris, FRANCE
Posts: 132
I just tryied something like that
Code:
SELECT
	GROUP_CONCAT(DISTINCT tmp.cat) AS "cat"
	, CONCAT(tmp.nom, " ", tmp.prenom) AS "learner"
	, CONCAT(tmp.produit, " ", tmp.langue) AS "prod"
	, GROUP_CONCAT(DISTINCT tmp.langue) AS "lang"
	, GROUP_CONCAT(DISTINCT tmp.division) AS "div"
	, GROUP_CONCAT(DISTINCT tmp.departement) AS "dept"
	, GROUP_CONCAT(DISTINCT tmp.centre) AS "center"
	, GROUP_CONCAT(DISTINCT tmp.tuteur) AS "tutor"
	, GROUP_CONCAT(DISTINCT tmp.date) AS "date"
	, DATE_FORMAT(tmp.date, "%M") AS "month"
	, DATE_FORMAT(tmp.date, "%d %b %y") AS "fdate"
	, GROUP_CONCAT(DISTINCT tmp.statut) AS "status"
	, CONCAT(tmp.division, " - ", tmp.langue) AS "div_lang"
	, GROUP_CONCAT(DISTINCT tmp.cost_center) AS "cost_center"
	, GROUP_CONCAT(DISTINCT tmp.matricule) AS "mat"
	, COUNT(DISTINCT IF(tmp.statut = "Present", tmp.sest_id, NULL)) AS "R"
	, COUNT(DISTINCT IF(tmp.statut = "Absent", tmp.sest_id, NULL)) AS "A"
	, COUNT(DISTINCT tmp.sest_id) AS "T"
FROM
	test_data AS tmp
WHERE
	tmp.statut <> ""
GROUP BY
	tmp.langue
	, tmp.tuteur
ORDER BY
	tmp.langue
	, tmp.tuteur
;
It's doing the same error
Reply With Quote
  #8 (permalink)  
Old 06-29-07, 04:14
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
It is difficult to debug your code as the field names don't make much sense to me and it's very difficult to understand what it is you want to do. Your last version of SQL is still mixed up between whether it wants to group the data or select it out individually. I suggest you find a web page dedicated to learning SQL and have a good look at what the group by command does. I hope the following works for you.

Code:
SELECT  DISTINCT tmp.cat AS "cat"
        , tmp.nom, " ", tmp.prenom AS "learner"
        , CONCAT(tmp.produit, " ", tmp.langue) AS "prod"
        , tmp.langue AS "lang"
        , tmp.division AS "div"
        , tmp.departement AS "dept"
        , tmp.centre AS "center"
        , tmp.tuteur AS "tutor"
        , tmp.date AS "date"
        , DATE_FORMAT(tmp.date, "%M") AS "month"
        , DATE_FORMAT(tmp.date, "%d %b %y") AS "fdate"
        , tmp.statut AS "status"
        , CONCAT(tmp.division, " - ", tmp.langue) AS "div_lang"
        , tmp.cost_center AS "cost_center"
        , tmp.matricule AS "mat"
        , IF(tmp.statut = "Present", tmp.sest_id, NULL) AS "R"
        , IF(tmp.statut = "Absent", tmp.sest_id, NULL) AS "A"
        , tmp.sest_id AS "T"
FROM    test_data AS tmp
WHERE   tmp.statut <> ""
GROUP BY tmp.langue , tmp.tuteur
ORDER BY tmp.langue , tmp.tuteur;
Reply With Quote
  #9 (permalink)  
Old 06-29-07, 04:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by mike_bike_kite
Either get rid of the aggregate functions and grouping or apply aggregates to all fields (that you're not grouping by).
that is not necessarily necessary

please read Debunking GROUP BY myths --
"It is completely safe to write partial GROUP BY clauses as long as all non-aggregated columns in the SELECT list are functionally dependent upon the GROUP BY clause. In fact, a partial GROUP BY list can result in better performance, because it keeps the server from evaluating the entire GROUP BY list."
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #10 (permalink)  
Old 06-29-07, 04:27
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by gtk
Can someone try with a version 4.1.x ?
ran your test data and query in 4.1.20-community-nt and it worked just fine

results of query:
Code:
cat	learner	prod	lang	div	dept	center	tutor	date	month	fdate	status	div_lang	cost_center	mat	R	A	T
Face à face	DREUILLAUD Sebastien	EN-Tutorat English	English	AAA		AAA	Altagracia MORENO	2007-05-23	May	23 May 07	Absent	AAA - English			36	6	42
Face à face	NIKITINE Boris	EN-Tutorat English	English	AAA		AAA	Claire BOOTH-VILAIN	2007-05-23	May	23 May 07	Present	AAA - English			1	0	1
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 06-29-07, 05:01
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Quote:
Originally Posted by mike_bike_kite
Either get rid of the aggregate functions and grouping or apply aggregates to all fields (that you're not grouping by).

Originally Posted by r937
that is not necessarily necessary
I stand corrected
Reply With Quote
  #12 (permalink)  
Old 06-29-07, 05:29
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
It's worth noting however that he is not grouping on a primary/unique key and thus he "ought" to adhere to utilising aggregates on his results, or including them in his group by clause as per SQL 99 (they are not functionally dependent columns)
Code:
	tmp.langue
	, tmp.tuteur
Reply With Quote
  #13 (permalink)  
Old 06-29-07, 18:21
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
Quote:
Originally Posted by r937
that is not necessarily necessary

please read Debunking GROUP BY myths --
"It is completely safe to write partial GROUP BY clauses as long as all non-aggregated columns in the SELECT list are functionally dependent upon the GROUP BY clause. In fact, a partial GROUP BY list can result in better performance, because it keeps the server from evaluating the entire GROUP BY list."
From same article:

What did we mean when we specified the birth column in the SELECT list?

There is no good answer to this question. It is certainly possible to select just one of the possible values for the birth column: in fact, this is exactly what MySQL does.


How is returning the wrong data "safe"?! MySQL has no way of knowing what is functionally dependent on what, so it should either provide such a facility or do the safe thing by default.
Reply With Quote
  #14 (permalink)  
Old 06-29-07, 18:23
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
well, there you go, that was the whole point of the article

obviously, that column was not dependent on the GROUP BY column

did you finish the article? it's explained in some detail

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #15 (permalink)  
Old 07-07-07, 01:40
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
Quote:
Originally Posted by r937
well, there you go, that was the whole point of the article

obviously, that column was not dependent on the GROUP BY column

did you finish the article? it's explained in some detail

I hate SQL's grouping and summaries facility, personally. So there's my bias: you can't make me happy either way.

Here's the bigger problem. If I do a relational operation on a table I get another table, right? But while we all know what data is returned by those operations, we are rarely cognizant of what structure the result has. Most DBMSs I've seen don't even show you the data types.

I know that I only ever worry about functional dependencies if it's not immediately obvious how to normalize a database. I certainly don't do that for derived tables, and I've never seen anyone note it down. And that's why I think he says this:

Of course, it is impossible to distinguish between a query that intentionally omits columns from the GROUP BY clause and one that accidentally forgot to include them.

If the DBMS had syntax like CREATE TABLE Foo (a AS INTEGER FUNC DEP ON (b, c), ...) it could tell you when you were using a partial grouping clause incorrectly. I'd be fine with partial GROUP BY clauses in that case.

Even with a saavy DBA it seems far more likely that a partial GROUP BY would be due to adding a field and not updating a query. This feature, then, is much more likely to lead to bugs than to any useful optimization.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On