Background

We often encounter situations where the execution time of the corresponding SQL is less than expected. In order to optimize the SQL to achieve the expected Query delay, through the Profile we can see what optimizations can be done. Now we will explain how to get the Profile corresponding to the Query in different environments.

Request

HTTP://FE_IP:HTTP_PORT GET /API/Profile

The Doris cluster can normally access the external network

  1. Enable profile reporting parameters enable_profile

    This parameter turns on the session variable. It is not recommended to turn this variable on globally.

    1. --open variable
    2. mysql> set enable_profile=true;
    3. Query OK, 0 rows affected (0.00 sec)
    4. --Confirm whether the variable is opened normally
    5. mysql> show variables like '%profile%';
    6. +----------------+-------+---------------+---------+
    7. | Variable_name | Value | Default_Value | Changed |
    8. +----------------+-------+---------------+---------+
    9. | enable_profile | true | false | 1 |
    10. +----------------+-------+---------------+---------+
    11. 1 row in set (0.00 sec)
  2. Execute the corresponding query

    In the case of a cluster with multiple fes, you need to execute the corresponding query on the fes that enable profile reporting parameters. The parameters do not take effect globally.

    1. --open variable
    2. mysql> set enable_profile=true;
    3. Query OK, 0 rows affected (0.00 sec)
    4. --Confirm whether the variable is opened normally
    5. mysql> show variables like '%profile%';
    6. +----------------+-------+---------------+---------+
    7. | Variable_name | Value | Default_Value | Changed |
    8. +----------------+-------+---------------+---------+
    9. | enable_profile | true | false | 1 |
    10. +----------------+-------+---------------+---------+
    11. 1 row in set (0.00 sec)
    12. --Execute the corresponding Query
    13. mysql> select id,name from test.test where name like "%RuO%";
    14. +---------------------------+-----------------------------------------------------------------------------------------------------------------------------+
    15. | id | name |
    16. +---------------------------+-----------------------------------------------------------------------------------------------------------------------------+
    17. | 1ZWXYGbb8nr5Pi29J4cEMyEMb | ZN1nqzBRSl1rTrr99rnX1aplxhRuOUTLw6so7rzjlRQ317gTPxh0dHljmrARDJjH7FjRkJW9c7YuUBmWikq7eNgmFKJPreWirDrGrFzUYH4eP6kDtSA3UTnNIIj |
    18. +---------------------------+-----------------------------------------------------------------------------------------------------------------------------+
    19. 1 row in set (0.01 sec)
  3. Get Profile

    When the cluster has multiple fes, you need to access the QueryProfile page of the FE HTTP interface (HTTP://FE_IP:HTTP_PORT) that executes the corresponding query. Click the corresponding Profile ID to view the corresponding Profile. You can also download the corresponding Profile in the Profile interface.

    profile1.png profile2.png

Doris cluster’s access to the external network is restricted

When the cluster cannot access the external network normally, it needs to obtain the corresponding profile through the API (HTTP://FE_IP:HTTP_PORT/API/Profile?Query_ID=). The IP and PORT refer to the IP and PORT corresponding to FE that executes the corresponding Query. At this time, the first two steps of obtaining the Profile corresponding to the Query are the same as when accessing the external network normally. There will be a difference in the third step of obtaining the Profile.

Get Profile

  • Find the corresponding Profile ID

    1. --Find the Profile ID according to the corresponding query
    2. mysql> show query profile "/";
    3. +-----------------------------------+-----------+---------------------+---------------------+-------+------------+------+------------+-------------------------------------------------------+
    4. | Profile ID | Task Type | Start Time | End Time | Total | Task State | User | Default Db | Sql Statement |
    5. +-----------------------------------+-----------+---------------------+---------------------+-------+------------+------+------------+-------------------------------------------------------+
    6. | 1b0bb22689734d30-bbe56e17c2ff21dc | QUERY | 2024-02-28 11:00:17 | 2024-02-28 11:00:17 | 7ms | EOF | root | | select id,name from test.test where name like "%RuO%" |
    7. | 202fb174510c4772-965289e8f7f0cf10 | QUERY | 2024-02-25 19:39:20 | 2024-02-25 19:39:20 | 19ms | EOF | root | | select id,name from test.test where name like "%KJ%" |
    8. +-----------------------------------+-----------+---------------------+---------------------+-------+------------+------+------------+-------------------------------------------------------+
    9. 2 rows in set (0.00 sec)
  • Query Profile and redirect Profile to a text

    1. template: curl -X GET -u user:password http://fe_ip:http_port/api/profile?query_id=1b0bb22689734d30-bbe56e17c2ff21dc > test.profile
    2. [user@VM-10-6-centos profile]$ curl -X GET -u root:root http://127.0.0.1:8030/api/profile?query_id=1b0bb22689734d30-bbe56e17c2ff21dc > test.profile
    3. % Total % Received % Xferd Average Speed Time Time Time Current
    4. Dload Upload Total Spent Left Speed
    5. 100 1211 0 1211 0 0 168k 0 --:--:-- --:--:-- --:--:-- 168k
  • The returned Profile line break is \ \n, which is inconvenient to analyze. You can replace \ \n with \n in a text editing tool.

    1. [user@VM-10-6-centos profile]$ cat test.profile
    2. {"msg":"success","code":0,"data":{"profile":"Query:\n Summary:\n
    3. - Profile ID: 1b0bb22689734d30-bbe56e17c2ff21dc\n - Task Type: QUERY\n
    4. - Start Time: 2024-02-28 11:00:17\n - End Time: 2024-02-28 11:00:17\n
    5. - Total: 7ms\n - Task State: EOF\n - User: root\n - Default Db: \n
    6. - Sql Statement: select id,name from test.test where name like \"%RuO%\"\n Execution Summary:\n
    7. - Workload Group: \n - Analysis Time: 1ms\n
    8. - Plan Time: 2ms\n - JoinReorder Time: N/A\n
    9. - CreateSingleNode Time: N/A\n - QueryDistributed Time: N/A\n
    10. - Init Scan Node Time: N/A\n - Finalize Scan Node Time: N/A\n
    11. - Get Splits Time: N/A\n - Get PARTITIONS Time: N/A\n
    12. - Get PARTITION FILES Time: N/A\n - Create Scan Range Time: N/A\n
    13. - Schedule Time: N/A\n - Fetch Result Time: 0ms\n - Write Result Time: 0ms\n
    14. - Wait and Fetch Result Time: N/A\n - Doris Version: doris-2.0.4-rc06-003a815b63\n
    15. - Is Nereids: Yes\n - Is Pipeline: Yes\n - Is Cached: Yes\n
    16. - Total Instances Num: 0\n - Instances Num Per BE: \n
    17. - Parallel Fragment Exec Instance Num: 48\n - Trace ID: \n"},"count":0}
  • The effect after replacement is as follows

    1. {"msg":"success","code":0,"data":{"profile":"Query:
    2. Summary:
    3. - Profile ID: 1b0bb22689734d30-bbe56e17c2ff21dc
    4. - Task Type: QUERY
    5. - Start Time: 2024-02-28 11:00:17
    6. - End Time: 2024-02-28 11:00:17
    7. - Total: 7ms
    8. - Task State: EOF
    9. - User: root
    10. - Default Db:
    11. - Sql Statement: select id,name from test.test where name like \"%RuO%\"
    12. Execution Summary:
    13. - Workload Group:
    14. - Analysis Time: 1ms
    15. - Plan Time: 2ms
    16. - JoinReorder Time: N/A
    17. - CreateSingleNode Time: N/A
    18. - QueryDistributed Time: N/A
    19. - Init Scan Node Time: N/A
    20. - Finalize Scan Node Time: N/A
    21. - Get Splits Time: N/A
    22. - Get PARTITIONS Time: N/A
    23. - Get PARTITION FILES Time: N/A
    24. - Create Scan Range Time: N/A
    25. - Schedule Time: N/A
    26. - Fetch Result Time: 0ms
    27. - Write Result Time: 0ms
    28. - Wait and Fetch Result Time: N/A
    29. - Doris Version: doris-2.0.4-rc06-003a815b63
    30. - Is Nereids: Yes
    31. - Is Pipeline: Yes
    32. - Is Cached: Yes
    33. - Total Instances Num: 0
    34. - Instances Num Per BE:
    35. - Parallel Fragment Exec Instance Num: 48
    36. - Trace ID:
    37. "},"count":0}