packages/sql-semantics-mysql/bench/StatementBench.php

1<?php
2
3declare(strict_types=1);
4
5namespace Bench;
6
7use PhpBench\Attributes as Bench;
8use SqlSemantics\Platform\MySql\Mode;
9use SqlSemantics\Platform\MySql\Semantics;
10
11/**
12 * Measures the analysis of a statement: parsing, lowering, derivation and rendering with its checks.
13 */
14#[Bench\Revs(10)]
15#[Bench\Iterations(3)]
16final class StatementBench
17{
18    /**
19     * Analyzes a grouped join with a window, ordering and limit on the latest release and writes it back.
20     */
21    public function benchSelect(): void
22    {
23        $semantics = new Semantics();
24        $semantics->analyze("SELECT t.a, COUNT(*) AS n, 'label', 0x1F, @@session.sql_mode, ROW_NUMBER() OVER w FROM shop.t AS t LEFT JOIN u USING (id) WHERE t.b > 1 GROUP BY t.a WINDOW w AS (ORDER BY t.a) ORDER BY n DESC LIMIT 10");
25    }
26
27    /**
28     * Analyzes the same projection on MySQL 5.7 under ANSI_QUOTES and writes it back.
29     */
30    public function benchLegacySelect(): void
31    {
32        $semantics = new Semantics('mysql-5.7.44', Mode::fromString('ANSI_QUOTES'));
33        $semantics->analyze('SELECT t.a, "b" AS total, \'label\', ? FROM shop.t AS t WHERE t.a <=> NULL');
34    }
35}
36