From 672f0b317776fdbaf39d0916321405f28da5694f Mon Sep 17 00:00:00 2001 From: Joby Elliott Date: Fri, 17 Aug 2018 12:12:21 -0600 Subject: [PATCH] cleanup pgsql needs to be developed off on its own feature branch --- benchmark/results.txt | 23 ----- benchmark/run.php | 143 ------------------------------- src/Drivers/PostgreSQLDriver.php | 87 ------------------- 3 files changed, 253 deletions(-) delete mode 100644 benchmark/results.txt delete mode 100644 benchmark/run.php delete mode 100644 src/Drivers/PostgreSQLDriver.php diff --git a/benchmark/results.txt b/benchmark/results.txt deleted file mode 100644 index 07f78d7..0000000 --- a/benchmark/results.txt +++ /dev/null @@ -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 - diff --git a/benchmark/run.php b/benchmark/run.php deleted file mode 100644 index 6eaf699..0000000 --- a/benchmark/run.php +++ /dev/null @@ -1,143 +0,0 @@ - $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'; -} diff --git a/src/Drivers/PostgreSQLDriver.php b/src/Drivers/PostgreSQLDriver.php deleted file mode 100644 index 1c30dc6..0000000 --- a/src/Drivers/PostgreSQLDriver.php +++ /dev/null @@ -1,87 +0,0 @@ -=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;'; - } -}