|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Soluble\Schema\Source\Mysql; |
|
4
|
|
|
|
|
5
|
|
|
use Soluble\DbWrapper\Adapter\AdapterInterface; |
|
6
|
|
|
|
|
7
|
|
|
abstract class AbstractMysqlDriver implements MysqlDriverInterface |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var AdapterInterface |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $adapter; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Schema name. |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $schema; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Used to restore innodb stats mysql global variable. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $mysql_innodbstats_value; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param AdapterInterface $adapter |
|
30
|
|
|
* @param string $schema database name |
|
31
|
|
|
*/ |
|
32
|
23 |
|
public function __construct(AdapterInterface $adapter, $schema) |
|
33
|
|
|
{ |
|
34
|
23 |
|
$this->adapter = $adapter; |
|
35
|
23 |
|
$this->schema = $schema; |
|
36
|
23 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Disable innodbstats will increase speed of metadata lookups. |
|
40
|
|
|
*/ |
|
41
|
4 |
|
protected function disableInnoDbStats() |
|
42
|
|
|
{ |
|
43
|
4 |
|
$sql = "show global variables like 'innodb_stats_on_metadata'"; |
|
44
|
|
|
try { |
|
45
|
4 |
|
$results = $this->adapter->query($sql); |
|
46
|
4 |
|
if (count($results) > 0) { |
|
47
|
4 |
|
$row = $results->offsetGet(0); |
|
48
|
|
|
|
|
49
|
4 |
|
$value = strtoupper($row['Value']); |
|
50
|
|
|
// if 'on' no need to do anything |
|
51
|
4 |
|
if ($value != 'OFF') { |
|
52
|
|
|
$this->mysql_innodbstats_value = $value; |
|
53
|
|
|
// disabling innodb_stats |
|
54
|
4 |
|
$this->adapter->query("set global innodb_stats_on_metadata='OFF'"); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} catch (\Exception $e) { |
|
58
|
|
|
// do nothing, silently fallback |
|
59
|
|
|
} |
|
60
|
4 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Restore old innodbstats variable. |
|
64
|
|
|
*/ |
|
65
|
4 |
|
protected function restoreInnoDbStats() |
|
66
|
|
|
{ |
|
67
|
4 |
|
$value = $this->mysql_innodbstats_value; |
|
68
|
4 |
|
if ($value !== null) { |
|
69
|
|
|
// restoring old variable |
|
70
|
|
|
$this->adapter->query("set global innodb_stats_on_metadata='$value'"); |
|
71
|
|
|
} |
|
72
|
4 |
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|