QueryStatsTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace YdbPlatform\Ydb\Test;
  3. use PHPUnit\Framework\TestCase;
  4. use YdbPlatform\Ydb\Enums\CollectQueryStatsMode;
  5. use YdbPlatform\Ydb\Session;
  6. use YdbPlatform\Ydb\Ydb;
  7. use YdbPlatform\Ydb\YdbTable;
  8. class QueryStatsTest extends TestCase{
  9. /**
  10. * @var \YdbPlatform\Ydb\Table
  11. */
  12. protected $table;
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. $config = [
  17. // Database path
  18. 'database' => '/local',
  19. // Database endpoint
  20. 'endpoint' => 'localhost:2136',
  21. // Auto discovery (dedicated server only)
  22. 'discovery' => false,
  23. // IAM config
  24. 'iam_config' => [
  25. 'anonymous' => true,
  26. 'insecure' => true,
  27. ],
  28. ];
  29. $ydb = new Ydb($config);
  30. $this->table = $ydb->table();
  31. }
  32. public function testGetNullQueryStatsWithBasicParameter(){
  33. $table = $this->table;
  34. $table->retryTransaction(function (Session $session){
  35. $result = $session->query('SELECT 1;', null, [
  36. 'collectStats' => CollectQueryStatsMode::STATS_COLLECTION_BASIC
  37. ]);
  38. self::assertNotNull($result->getQueryStats());
  39. }, true);
  40. }
  41. public function testGetNullQueryStatsWithFullParameter(){
  42. $table = $this->table;
  43. $table->retryTransaction(function (Session $session){
  44. $result = $session->query('SELECT 1;', null, [
  45. 'collectStats' => CollectQueryStatsMode::STATS_COLLECTION_FULL
  46. ]);
  47. self::assertNotNull($result->getQueryStats());
  48. self::assertNotEquals(0, count($result->getQueryStats()->getQueryPhases()));
  49. self::assertNotNull($result->getQueryStats()->getCompilation());
  50. self::assertNotEquals("", $result->getQueryStats()->getQueryPlan());
  51. }, true);
  52. }
  53. public function testGetNullQueryStatsWithoutParameter(){
  54. $this->table->retryTransaction(function (Session $session){
  55. $result = $session->query('SELECT 1;', null);
  56. self::assertNull($result->getQueryStats());
  57. }, true);
  58. }
  59. public function testGetNullQueryStatsWithNoneParameter(){
  60. $this->table->retryTransaction(function (Session $session){
  61. $result = $session->query('SELECT 1;', null, [
  62. 'collectStats' => CollectQueryStatsMode::STATS_COLLECTION_NONE
  63. ]);
  64. self::assertNull($result->getQueryStats());
  65. }, true);
  66. }
  67. }