pgsql needs to be developed off on its own feature branch
This commit is contained in:
Joby Elliott 2018-08-17 12:12:21 -06:00
parent a42374239e
commit 672f0b3177
3 changed files with 0 additions and 253 deletions

View file

@ -1,23 +0,0 @@
Date: 2018-08-10T03:16:29+01:00
Machine: PAULZE
Ops per: 1000
Each result is the average number of milliseconds it took to complete each operation. Lower is better.
Digraph\Destructr\Drivers\MySQLDriver
insert: 30.19ms
update: 31.07ms
search vcol: 147.44ms
search json: 154.34ms
Digraph\Destructr\LegacyDrivers\MySQL56Driver
insert: 32.89ms
update: 25.11ms
search vcol: 174.05ms
search json: 192.56ms
Digraph\Destructr\LegacyDrivers\SQLiteDriver
insert: 140.28ms
update: 145.12ms
search vcol: 157.92ms
search json: 165.01ms

View file

@ -1,143 +0,0 @@
<?php
/**
* This benchmarking script uses the same connection settings as the unit tests,
* so if you've got that working it should work too.
*/
include_once __DIR__.'/../vendor/autoload.php';
use Digraph\Destructr\Factory;
use Digraph\Destructr\Drivers\MySQLDriver;
use Digraph\Destructr\LegacyDrivers\SQLiteDriver;
use Digraph\Destructr\LegacyDrivers\MySQL56Driver;
const OPS_PER = 1000;
$dsos = [];
$out = [];
$out[] = 'Date: '.date('c');
$out[] = 'Machine: '.gethostname();
$out[] = 'Ops per: '.OPS_PER;
$out[] = 'Each result is the average number of milliseconds it took to complete each operation. Lower is better.';
$out[] = '';
foreach (drivers_list() as $class => $config) {
$driver = new $class(@$config['dsn'], @$config['username'], @$config['password'], @$config['options']);
$factory = new Factory($driver, $config['table']);
$factory->createTable();
benchmark_empty($factory);
$out[] = $class;
$out[] = benchmark_insert($factory);
$out[] = benchmark_update($factory);
$out[] = benchmark_search_vcol($factory);
$out[] = benchmark_search_json($factory);
$out[]= '';
}
$out[] = '';
file_put_contents(__DIR__.'/results.txt', implode(PHP_EOL, $out));
/**
* The classes and connection settings for benchmarking
*/
function drivers_list()
{
@unlink(__DIR__.'/test.sqlite');
$out = [];
$out[MySQLDriver::class] = [
'table' => 'benchmark57',
'dsn' => 'mysql:host=127.0.0.1;dbname=phpunit',
'username' => 'travis'
];
$out[MySQL56Driver::class] = [
'table' => 'benchmark56',
'dsn' => 'mysql:host=127.0.0.1;dbname=phpunit',
'username' => 'travis'
];
$out[SQLiteDriver::class] = [
'table' => 'benchmark',
'dsn' => 'sqlite:'.__DIR__.'/test.sqlite'
];
return $out;
}
/**
* Empties a table before beginning
*/
function benchmark_empty(&$factory)
{
global $dsos;
$dsos = [];
foreach ($factory->search()->execute([], null) as $o) {
$o->delete(true);
}
}
/**
* Benchmark insert operations
*/
function benchmark_insert(&$factory)
{
global $dsos;
$start = microtime(true);
for ($i=0; $i < OPS_PER; $i++) {
$dsos[$i] = $factory->create(
[
'dso.id'=>'benchmark-'.$i,
'dso.type'=>'benchmark-'.($i%2?'odd':'even'),
'benchmark.mod'=>($i%2?'odd':'even')
]
);
$dsos[$i]->insert();
}
$end = microtime(true);
$per = round(($end-$start)*100000/OPS_PER)/100;
return 'insert: '.$per.'ms';
}
/**
* Benchmark update operations
*/
function benchmark_update(&$factory)
{
global $dsos;
$start = microtime(true);
for ($i=0; $i < OPS_PER; $i++) {
$dsos[$i]['benchmark.int'] = $i;
$dsos[$i]['benchmark.string'] = 'benchmark-'.$i;
$dsos[$i]->update();
}
$end = microtime(true);
$per = round(($end-$start)*100000/OPS_PER)/100;
return 'update: '.$per.'ms';
}
/**
* Benchmark searching on a vcol
*/
function benchmark_search_vcol(&$factory)
{
$start = microtime(true);
for ($i=0; $i < OPS_PER; $i++) {
$search = $factory->search();
$search->where('${dso.type} = :type');
$search->execute([':type'=>'benchmark-odd']);
}
$end = microtime(true);
$per = round(($end-$start)*100000/OPS_PER)/100;
return 'search vcol: '.$per.'ms';
}
/**
* Benchmark searching on a JSON value
*/
function benchmark_search_json(&$factory)
{
$start = microtime(true);
for ($i=0; $i < OPS_PER; $i++) {
$search = $factory->search();
$search->where('${benchmark.mod} = :type');
$search->execute([':type'=>'even']);
}
$end = microtime(true);
$per = round(($end-$start)*100000/OPS_PER)/100;
return 'search json: '.$per.'ms';
}

View file

@ -1,87 +0,0 @@
<?php
/* Digraph CMS: Destructr | https://github.com/digraphcms/destructr | MIT License */
namespace Digraph\Destructr\Drivers;
/**
* What this driver supports: PostgreSQL >=9.3
*
* Eventually, anyway. At the moment it's untested and probably doesn't work.
*/
class PostgreSQLDriver extends AbstractDriver
{
/**
* Within the search we expand strings like ${dso.id} into JSON queries.
* Note that the Search will have already had these strings expanded into
* column names if there are virtual columns configured for them. That
* happens in the Factory before it gets here.
*/
protected function sql_select($args)
{
//extract query parts from Search and expand paths
$where = $this->expandPaths($args['search']->where());
$order = $this->expandPaths($args['search']->order());
$limit = $args['search']->limit();
$offset = $args['search']->offset();
//select from
$out = ["SELECT * FROM `{$args['table']}`"];
//where statement
if ($where !== null) {
$out[] = "WHERE ".$where;
}
//order statement
if ($order !== null) {
$out[] = "ORDER BY ".$order;
}
//limit
if ($limit !== null) {
$out[] = "LIMIT ".$limit;
}
//offset
if ($offset !== null) {
$out[] = "OFFSET ".$offset;
}
//return
return implode(PHP_EOL, $out).';';
}
protected function sql_ddl($args=array())
{
$out = [];
$out[] = "CREATE TABLE `{$args['table']}` (";
$lines = [];
$lines[] = "`json_data` JSON DEFAULT NULL";
foreach ($args['virtualColumns'] as $path => $col) {
$lines[] = "`{$col['name']}` {$col['type']} GENERATED ALWAYS AS (".$this->expandPath($path).") VIRTUAL";
}
foreach ($args['virtualColumns'] as $path => $col) {
if (@$col['unique'] && $as = @$col['index']) {
$lines[] = "UNIQUE KEY `{$args['table']}_{$col['name']}_idx` (`{$col['name']}`) USING $as";
} elseif ($as = @$col['index']) {
$lines[] = "KEY `{$args['table']}_{$col['name']}_idx` (`{$col['name']}`) USING $as";
}
}
$out[] = implode(','.PHP_EOL, $lines);
$out[] = ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
return implode(PHP_EOL, $out);
}
protected function expandPath(string $path) : string
{
return "JSON_UNQUOTE(JSON_EXTRACT(`json_data`,'$.{$path}'))";
}
protected function sql_setJSON($args)
{
return 'UPDATE `'.$args['table'].'` SET `json_data` = :data WHERE `dso_id` = :dso_id;';
}
protected function sql_insert($args)
{
return "INSERT INTO `{$args['table']}` (`json_data`) VALUES (:data);";
}
protected function sql_delete($args)
{
return 'DELETE FROM `'.$args['table'].'` WHERE `dso_id` = :dso_id;';
}
}