New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide explain plan feature #315
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
03dda95
Add doExplainPlan on DBAdapter
ddalmais f0c8673
Add specific Mysql doExplainPlan function
ddalmais 9f16429
Add explain function
ddalmais 2f6a4fa
Add explain plan unit test on mysql bookstore
ddalmais 00bcc96
Fix text in ExplainPlanTest
ddalmais a8c55fd
Enable doExplainPlan to take a binded query
cedriclombardot f62cba4
Enable to get the connection name in log
cedriclombardot e4c3de1
Fix phpdoc function title
ddalmais d54388a
Remove forced database read connection
ddalmais 2420c3e
Add DBOracle doExplainPlan function
ddalmais 377baf9
Add unit test on getExplainPlanQuery
ddalmais 460b90f
Make ExplainPlanTest independent from Adapter
ddalmais 0469a2c
Format DBMysql code
ddalmais 929080d
Add unit test on explain plan compute from text query
ddalmais aeeb66d
Fix text formatting
ddalmais 2e74a91
Fix indentation and useless blank line
ddalmais 4c8d9ac
Use assertArrayHasKey instead of assertTrue
ddalmais 4cb3e5e
Fix CS
ddalmais File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Propel package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
|
||
require_once dirname(__FILE__) . '/../../../tools/helpers/bookstore/BookstoreTestBase.php'; | ||
require_once dirname(__FILE__) . '/../../../tools/helpers/bookstore/BookstoreDataPopulator.php'; | ||
|
||
/** | ||
* Test class for SubQueryTest. | ||
* | ||
* @author Francois Zaninotto | ||
* @version $Id$ | ||
* @package runtime.query | ||
*/ | ||
class ExplainPlanTest extends BookstoreTestBase | ||
{ | ||
public function testExplainPlanFromObject() | ||
{ | ||
BookstoreDataPopulator::depopulate($this->con); | ||
BookstoreDataPopulator::populate($this->con); | ||
|
||
$db = Propel::getDb(BookPeer::DATABASE_NAME); | ||
|
||
$c = new ModelCriteria('bookstore', 'Book'); | ||
$c->join('Book.Author'); | ||
$c->where('Author.FirstName = ?', 'Neal'); | ||
$c->select('Title'); | ||
$explain = $c->explain($this->con); | ||
|
||
if ($db instanceof DBMySQL) { | ||
$this->assertEquals(sizeof($explain), 2, 'Explain plan return two lines'); | ||
|
||
// explain can change sometime, test can't be strict | ||
$this->assertArrayHasKey('select_type',$explain[0], 'Line 1, select_type key exist'); | ||
$this->assertArrayHasKey('table',$explain[0], 'Line 1, table key exist'); | ||
$this->assertArrayHasKey('type',$explain[0], 'Line 1, type key exist'); | ||
$this->assertArrayHasKey('possible_keys',$explain[0], 'Line 1, possible_keys key exist'); | ||
|
||
$this->assertArrayHasKey('select_type',$explain[1], 'Line 2, select_type key exist'); | ||
$this->assertArrayHasKey('table',$explain[1], 'Line 2, table key exist'); | ||
$this->assertArrayHasKey('type',$explain[1], 'Line 2, type key exist'); | ||
$this->assertArrayHasKey('possible_keys',$explain[1], 'Line 2, possible_keys key exist'); | ||
} elseif($db instanceof DBOracle) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it should be |
||
$this->assertTrue(sizeof($explain) > 2, 'Explain plan return more than 2 lines'); | ||
} else { | ||
$this->markTestSkipped('Cannot test explain plan on adapter ' . get_class($db)); | ||
} | ||
} | ||
|
||
public function testExplainPlanFromString() | ||
{ | ||
BookstoreDataPopulator::depopulate($this->con); | ||
BookstoreDataPopulator::populate($this->con); | ||
|
||
$db = Propel::getDb(BookPeer::DATABASE_NAME); | ||
|
||
$query = 'SELECT book.TITLE AS Title FROM book INNER JOIN author ON (book.AUTHOR_ID=author.ID) WHERE author.FIRST_NAME = \'Neal\''; | ||
$stmt = $db->doExplainPlan($this->con, $query); | ||
$explain = $stmt->fetchAll(PDO::FETCH_ASSOC); | ||
|
||
if ($db instanceof DBMySQL) { | ||
$this->assertEquals(sizeof($explain), 2, 'Explain plan return two lines'); | ||
|
||
// explain can change sometime, test can't be strict | ||
$this->assertArrayHasKey('select_type',$explain[0], 'Line 1, select_type key exist'); | ||
$this->assertArrayHasKey('table',$explain[0], 'Line 1, table key exist'); | ||
$this->assertArrayHasKey('type',$explain[0], 'Line 1, type key exist'); | ||
$this->assertArrayHasKey('possible_keys',$explain[0], 'Line 1, possible_keys key exist'); | ||
|
||
$this->assertArrayHasKey('select_type',$explain[1], 'Line 2, select_type key exist'); | ||
$this->assertArrayHasKey('table',$explain[1], 'Line 2, table key exist'); | ||
$this->assertArrayHasKey('type',$explain[1], 'Line 2, type key exist'); | ||
$this->assertArrayHasKey('possible_keys',$explain[1], 'Line 2, possible_keys key exist'); | ||
} elseif($db instanceof DBOracle) { | ||
$this->assertTrue(sizeof($explain) > 2, 'Explain plan return more than 2 lines'); | ||
} else { | ||
$this->markTestSkipped('Cannot test explain plan on adapter ' . get_class($db)); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should add a blank line before the return statement