MySQL Forums
Forum List  »  Performance

Query Slow
Posted by: Vitor Vitor
Date: October 08, 2013 12:25PM

Hi everybody, someone can explain me?

mysql> select * from log_funcionario where cod_log in (select max(cod_log) from log_funcionario where cod_funcionario="51" and tipo = 'logado');
+---------+-----------------+-----------+---------------------+---------------------+--------+
| cod_log | cod_funcionario | protocolo | data_inicio | data_fim | tipo |
+---------+-----------------+-----------+---------------------+---------------------+--------+
| 26432 | 51 | NULL | 2013-10-07 14:59:26 | 2013-10-07 18:03:25 | logado |
+---------+-----------------+-----------+---------------------+---------------------+--------+
1 row in set (3 min 30.80 sec)



Now in parts:

mysql> select max(cod_log) from log_funcionario where cod_funcionario="51" and tipo = 'logado';
+--------------+
| max(cod_log) |
+--------------+
| 26432 |
+--------------+
1 row in set (0.01 sec)


mysql> select * from log_funcionario where cod_log in (26432);
+---------+-----------------+-----------+---------------------+---------------------+--------+
| cod_log | cod_funcionario | protocolo | data_inicio | data_fim | tipo |
+---------+-----------------+-----------+---------------------+---------------------+--------+
| 26432 | 51 | NULL | 2013-10-07 14:59:26 | 2013-10-07 18:03:25 | logado |
+---------+-----------------+-----------+---------------------+---------------------+--------+
1 row in set (0.00 sec)


And now another code:
mysql> select * from log_funcionario where cod_funcionario="51" and tipo = 'logado' order by cod_log desc limit 0,1;
+---------+-----------------+-----------+---------------------+---------------------+--------+
| cod_log | cod_funcionario | protocolo | data_inicio | data_fim | tipo |
+---------+-----------------+-----------+---------------------+---------------------+--------+
| 26432 | 51 | NULL | 2013-10-07 14:59:26 | 2013-10-07 18:03:25 | logado |
+---------+-----------------+-----------+---------------------+---------------------+--------+
1 row in set (0.00 sec)



The table's backup: http://www.4shared.com/document/X11Set51/h_log_f.html

Options: ReplyQuote


Subject
Views
Written By
Posted
Query Slow
1611
October 08, 2013 12:25PM
850
October 08, 2013 12:34PM
1680
October 10, 2013 09:50PM
791
October 11, 2013 07:31AM
919
October 12, 2013 01:24PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.