Querys Bug

Reply

Join Date: Jun 2008
Posts: 3
Reputation: dispy is an unknown quantity at this point 
Solved Threads: 0
dispy dispy is offline Offline
Newbie Poster

Querys Bug

 
0
  #1
Jun 23rd, 2008
Good day

<<== new, please excuse If I post shit

I've one query which doesn't work:
  1. SELECT
  2. conquer.TIMESTAMP AS TIME,
  3. conquer.new_owner AS new_owner_id
  4.  
  5. FROM de12_conquer AS conquer
  6. INNER JOIN de12_tribe AS conqueror ON conqueror.id=conquer.new_owner
  7. INNER JOIN de12_tribe AS loser ON loser.id=conquer.old_owner
  8.  
  9. WHERE (conquer.timestamp>0 && conquer.timestamp<1213647029734) AND (conqueror.ally=37038 OR loser.ally=37038 )
  10. ORDER BY conquer.TIMESTAMP DESC LIMIT 50

This query doesn't work .... mysql server has gone away is the return or nothing... just loading

I've located the problem with a second query which works:
  1. SELECT
  2. conquer.TIMESTAMP AS TIME,
  3. conquer.new_owner AS new_owner_id
  4.  
  5. FROM de12_conquer AS conquer
  6. INNER JOIN de12_tribe AS conqueror ON conqueror.id=conquer.new_owner
  7.  
  8. WHERE (conquer.timestamp>0 && conquer.timestamp<1213647029734) AND (conqueror.ally=37038 )
  9. ORDER BY conquer.TIMESTAMP DESC LIMIT 50

As you can see the both query have only 1 different INNER JOIN (ignore the additional where-condition):
  1. INNER JOIN de12_tribe AS loser ON loser.id=conquer.old_owner

This line is "crashing" MySQl... but why ????

Structures of the tables:
  1. CREATE TABLE IF NOT EXISTS `de12_tribe` (
  2. `id` INT(11) NOT NULL,
  3. `name` VARCHAR(50) NOT NULL DEFAULT '',
  4. `ally` INT(11) NOT NULL,
  5. `villages` INT(5) NOT NULL,
  6. `points` INT(11) NOT NULL,
  7. `rank` INT(5) NOT NULL,
  8. PRIMARY KEY (`id`)
  9. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

  1. CREATE TABLE IF NOT EXISTS `de12_conquer` (
  2. `villageid` INT(11) NOT NULL,
  3. `TIMESTAMP` INT(11) NOT NULL,
  4. `new_owner` INT(11) NOT NULL,
  5. `old_owner` INT(11) NOT NULL,
  6. KEY `villageid` (`villageid`),
  7. KEY `TIMESTAMP` (`TIMESTAMP`),
  8. KEY `new_owner` (`new_owner`),
  9. KEY `old_owner` (`old_owner`)
  10. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

I hope you can help me, thanks !!

dispy
Last edited by dispy; Jun 23rd, 2008 at 3:46 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: tesuji is on a distinguished road 
Solved Threads: 42
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: Querys Bug

 
0
  #2
Jun 23rd, 2008
Hi

What exactly do you mean by:
"This query doesn't work .... mysql server has gone away is the return or nothing... just loading" ?

Do you get any error message?
Does the query never ends?
Is the result set empty? (because of improper data you want to join together. for example: if old_owner of table del2_conquer and id of del2_tribe do not have same values, your result set would be empty.)

How large are both tables, current number of rows per table? Depending on size and features needed sometimes innodb is more useful than myisam.

Second table does not have primary key, also no foreign keys (sorry, fk not possible for myisam). I am trying to figure out which relationship exists between both tables, and I have got the feeling that the table's structure wouldn't that be optimal. As for example villages of del2_tribe could appear several times for same tribe. On the other hand there is villageid of second table, how is it related to first table (via villages)?

ok, maybe above will get you some ideas to proceed solving your problem.

krs,
tesu
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 79
Reputation: varmadba is an unknown quantity at this point 
Solved Threads: 8
varmadba varmadba is offline Offline
Junior Poster in Training

Re: Querys Bug

 
0
  #3
Jun 24th, 2008
if you run a explain on your query it shows

"Impossible WHERE noticed after reading const tables"

that's because

[code] WHERE conquer.timestamp between 0 and 1213647029734 [\code]

In table de12_conquer ,timestamp columns is a integer data type and this number cant be inserted into it

The value you are using (1213647029734) is worng,it not a UNIXTIME or a timestamp value

let me know if it helps....
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 3
Reputation: dispy is an unknown quantity at this point 
Solved Threads: 0
dispy dispy is offline Offline
Newbie Poster

Re: Querys Bug

 
0
  #4
Jun 24th, 2008
"This query doesn't work .... mysql server has gone away is the return or nothing... just loading" ?

Do you get any error message?
Does the query never ends?
One time testing it I waited ~5 minutes and then I got the "mysql server has gone away"

Is the result set empty? (because of improper data you want to join together. for example: if old_owner of table del2_conquer and id of del2_tribe do not have same values, your result set would be empty.)
Possible, but there are records passing the conditions, I'm sure ^^
I've tried LEFT JOIN instead of INNER JOIN -that didn't work too.

Second table does not have primary key, also no foreign keys (sorry, fk not possible for myisam). I am trying to figure out which relationship exists between both tables, and I have got the feeling that the table's structure wouldn't that be optimal. As for example villages of del2_tribe could appear several times for same tribe. On the other hand there is villageid of second table, how is it related to first table (via villages)?
de12_conquer can't have a primary key - there isn't an id existing just one time

de12_tribe contains the tribe -there is a primary key cause the id of every player exists only one time.
A tribe can have multiple conquers logged in the table de12_conquer - new_owner and old_owner are the fields which contain the id of the tribe ( one the looser and one the winner).
It's for a tool for the browsergame tribalwars (to understand the relations ).

the villageid contains the ID (primary key) of the village (in de12_villages- for this problem not necessary).

Don't worry about the structure of the relations -they're correct

f you run a explain on your query it shows

"Impossible WHERE noticed after reading const tables"

that's because

[code] WHERE conquer.timestamp between 0 and 1213647029734 [\code]
Wrong -I already tried explain and I didn't get an error.
Here the explain-output:
  1. id select_type table type possible_keys key key_len ref rows Extra
  2. 1 SIMPLE loser ALL PRIMARY NULL NULL NULL 7616 USING temporary; USING filesort
  3. 1 SIMPLE conquer ref TIMESTAMP,new_owner,old_owner old_owner 4 dispy.loser.id 8 USING WHERE
  4. 1 SIMPLE conqueror ALL PRIMARY NULL NULL NULL 7616 Range checked for each record (index map: 0x1)

In table de12_conquer ,timestamp columns is a integer data type and this number cant be inserted into it

The value you are using (1213647029734) is worng,it not a UNIXTIME or a timestamp value
You're right: I'll fix that.

Thanks for trying to help me
dispy

EDIT: I forgot:
records in de12_conquer: 625,687
reconrds in de12_tribe:7,616
Last edited by dispy; Jun 24th, 2008 at 9:22 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 3
Reputation: dispy is an unknown quantity at this point 
Solved Threads: 0
dispy dispy is offline Offline
Newbie Poster

Re: Querys Bug

 
0
  #5
Jun 30th, 2008
No one has an idea? -.-
I know a toolsite solved this problem by using ORM (PHP, MySQL) but I need a "real" Query ^^

dispy
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the MySQL Forum


Views: 849 | Replies: 4
Thread Tools Search this Thread



Tag cloud for MySQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC