Created
February 19, 2014 16:00
-
-
Save hidayat365/9095005 to your computer and use it in GitHub Desktop.
EXPLAIN PLAN menjelaskan Query langsung terhadap table dan view adalah sama saja di MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> ------------------------------------- | |
mysql> ini execution plan | |
mysql> untuk query langsung ke base table | |
mysql> ------------------------------------- | |
mysql> explain | |
-> select a.*, b.account_id, b.item_id, b.debet, b.credit | |
-> from journals a | |
-> join journal_details b on a.id=b.journal_id | |
-> where a.id=1 ; | |
+----+-------------+-------+-------+-----------------------------+---------+---------+-------+------+-------------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+----+-------------+-------+-------+-----------------------------+---------+---------+-------+------+-------------+ | |
| 1 | SIMPLE | a | const | PRIMARY | PRIMARY | 4 | const | 1 | | | |
| 1 | SIMPLE | b | ALL | FK_journal_details_journals | NULL | NULL | NULL | 3 | Using where | | |
+----+-------------+-------+-------+-----------------------------+---------+---------+-------+------+-------------+ | |
2 rows in set (0.00 sec) | |
mysql> ------------------------------------- | |
mysql> coba kita buat view-nya - tanpa where | |
mysql> ------------------------------------- | |
mysql> create view view_data as | |
-> select a.*, b.account_id, b.item_id, b.debet, b.credit | |
-> from journals a | |
-> join journal_details b on a.id=b.journal_id ; | |
Query OK, 0 rows affected (0.05 sec) | |
mysql> ------------------------------------- | |
mysql> ini execution plan | |
mysql> untuk query langsung ke view | |
mysql> ------------------------------------- | |
mysql> explain | |
-> select * from view_data | |
-> where id=1 ; | |
+----+-------------+-------+-------+-----------------------------+---------+---------+-------+------+-------------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+----+-------------+-------+-------+-----------------------------+---------+---------+-------+------+-------------+ | |
| 1 | SIMPLE | a | const | PRIMARY | PRIMARY | 4 | const | 1 | | | |
| 1 | SIMPLE | b | ALL | FK_journal_details_journals | NULL | NULL | NULL | 3 | Using where | | |
+----+-------------+-------+-------+-----------------------------+---------+---------+-------+------+-------------+ | |
2 rows in set (0.00 sec) | |
mysql> ------------------------------------- | |
mysql> YAY....!!! | |
mysql> rupanya sama saja..... | |
mysql> ------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment