Merge branch 'MDL-39725_analyze' of https://github.com/mr-russ/moodle

Conflicts:
	lib/dml/moodle_database.php
This commit is contained in:
Sam Hemelryk 2013-12-17 09:31:19 +13:00
commit 9d771f9529
5 changed files with 48 additions and 4 deletions

View file

@ -1545,6 +1545,9 @@ class core_ddl_testcase extends database_driver_testcase {
$this->assertSame($records[1]->secondname, $this->records['test_table1'][0]->secondname);
$this->assertSame($records[2]->intro, $this->records['test_table1'][1]->intro);
// Collect statistics about the data in the temp table.
$DB->update_temp_table_stats();
// Drop table1.
$dbman->drop_table($table1);
$this->assertFalse($dbman->table_exists('test_table1'));
@ -1558,6 +1561,9 @@ class core_ddl_testcase extends database_driver_testcase {
$this->assertInstanceOf('ddl_table_missing_exception', $e);
}
// Collect statistics about the data in the temp table with less tables.
$DB->update_temp_table_stats();
// Fill/modify/delete a few table0 records.
// Drop table0.

View file

@ -2172,6 +2172,15 @@ abstract class moodle_database {
}
}
/**
* Analyze the data in temporary tables to force statistics collection after bulk data loads.
*
* @return void
*/
public function update_temp_table_stats() {
$this->temptables->update_stats();
}
/**
* Checks and returns true if transactions are supported.
*

View file

@ -22,6 +22,7 @@
*
* - databases not retrieving temp tables from information schema tables (mysql)
* - databases using a different name schema for temp tables (like mssql).
* - databases that don't collect planner stats for temp tables (like PgSQL).
*
* Basically it works as a simple store of created temporary tables, providing
* some simple getters/setters methods. Each database can extend it for its own
@ -31,9 +32,6 @@
* and the sql_generator, so both are able to use its facilities, with the final goal
* of doing temporary tables support 100% cross-db and transparent within the DB API.
*
* Only drivers needing it will use this store. Neither moodle_database (abstract) or
* databases like postgres need this, because they don't lack any temp functionality.
*
* @package core_dml
* @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@ -119,6 +117,17 @@ class moodle_temptables {
return null;
}
/**
* Analyze the data in temporary tables to force statistics collection after bulk data loads.
* The database class detects all temporary tables and will automatically analyze all created tables
*
* @return void
*/
public function update_stats() {
// By default most databases do automatic on temporary tables, PgSQL does not.
// As a result, update_stats call immediately return for non-interesting database types.
}
/**
* Dispose the temptables stuff, checking for wrong situations, informing and recovering from them
*/

View file

@ -29,5 +29,16 @@ defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/moodle_temptables.php');
class pgsql_native_moodle_temptables extends moodle_temptables {
// I love these classes :-P
/**
* Analyze the data in temporary tables to force statistics collection after bulk data loads.
* PostgreSQL does not natively support automatic temporary table stats collection, so we do it.
*
* @return void
*/
public function update_stats() {
$temptables = $this->get_temptables();
foreach ($temptables as $temptablename) {
$this->mdb->execute("ANALYZE {".$temptablename."}");
}
}
}

View file

@ -259,6 +259,7 @@ function stats_cron_daily($maxdays=1) {
$failed = true;
break;
}
$DB->update_temp_table_stats();
stats_progress('1');
@ -385,6 +386,10 @@ function stats_cron_daily($maxdays=1) {
$failed = true;
break;
}
// The steps up until this point, all add to {temp_stats_daily} and don't use new tables.
// There is no point updating statistics as they won't be used until the DELETE below.
$DB->update_temp_table_stats();
stats_progress('7');
// Default frontpage role enrolments are all site users (not deleted)
@ -581,6 +586,7 @@ function stats_cron_daily($maxdays=1) {
$failed = true;
break;
}
$DB->update_temp_table_stats();
stats_progress('15');
// How many view actions for guests or not-logged-in on frontpage
@ -1736,6 +1742,9 @@ function stats_temp_table_fill($timestart, $timeend) {
$DB->execute($sql);
// We have just loaded all the temp tables, collect statistics for that.
$DB->update_temp_table_stats();
return true;
}