save_query_result Support

After enabling save_query_result, MatrixOne will save the query results.

Three parameters affect the saving of query results:

  • save_query_result: enables/disables the saving of query results.
  • query_result_timeout: sets the time for saving query results.
  • query_result_maxsize: sets the maximum size of a single query result.

Enable save_query_result

Enable saving query results for the current session only:

  1. -- The default is off
  2. set global save_query_result = on
  • If you need to enable it globally, you can modify the configuration file cn.toml before starting MatrixOne, insert the following code, and save it:
  1. [cn.frontend]
  2. saveQueryResult = "on" // The default is off

Set the saving time

Set the save time unit to hours.

  • Enable query_result_timeout only for the current session:
  1. -- The default is 24
  2. set global query_result_timeout = 48
  • If you need to enable it globally, you can modify the configuration file cn.toml before starting MatrixOne, insert the following code, and save it:
  1. [cn.frontend]
  2. queryResultTimeout = 48 //The default is 24

Note: If the save time is set to a shorter value than the previous one, it will not affect the previous save results.

Set the maximum value of a single query result

Set the maximum unit of a single query result to MB.

  • Set the maximum value of query results for the current session only:
  1. -- The default is 100
  2. set global query_result_maxsize = 200
  • If you need to enable it globally, you can modify the configuration file cn.toml before starting MatrixOne, insert the following code, and save it:
  1. [cn.frontend]
  2. queryResultMaxsize = 200 // The default is 100

Note: If the maximum value of a single query result is set smaller than the previous setting, it will not affect the size of the last saved results.

Query metadata information

You can use the following SQL statement to query metadata information:

  1. select * from meta_scan(query_id) as u;
  2. 当前 account_id
  3. select query_id from meta_scan(query_id) as u;

The metadata information is as follows:

Column NameTypeRemarks
query_iduuidquery result ID
statementtextSQL statement executed
account_iduint32account ID
role_iduint32role ID
result_pathtextThe path to save the query results, the default is the mo-data/s3 path of the matrixone folder, if you want to modify the default path, you need to modify data-dir = “mo-data/s3” in the configuration file . For a description of configuration file parameters, see Common Parameter Configuration
created_timetimestampcreation time
result_sizefloatResult size in MB.
tablestexttables used by SQL
user_iduint32user ID
expired_timetimestamptimeout of query result
column_maptextIf the query has a column result name with the same name, the result scan will remap the column name

Save query results

You can store query results locally or in S3.

Syntax

  1. MODUMP QUERY_RESULT query_id INTO s3_path
  2. [FIELDS TERMINATED BY 'char']
  3. [ENCLOSED BY 'char']
  4. [LINES TERMINATED BY 'string']
  5. [header 'bool']
  6. [MAX_FILE_SIZE unsigned_number]
  • query_id: A string of UUID.

  • s3_path: the path where the query result file is saved. The default is the mo-data/s3 path in the matrixone folder. If you need to modify the default path, you must modify data-dir = "mo-data/s3" in the configuration file. For more information about configuration file parameters, see Common Parameter Configuration

  1. root@rootMacBook-Pro 02matrixone % cd matrixone/mo-data
  2. root@rootMacBook-Pro mo-data % ls
  3. dn-data etl local logservice-data s3

Note: If you need to export the csv file. The path needs to start with etl:.

  • [FIELDS TERMINATED BY ‘char’]: optional parameter. Field delimiter, the default is single quote '.

  • [ENCLOSED BY ‘char’]: optional parameter. Fields include symbols, which default to double quotes ".

  • [LINES TERMINATED BY ‘string’]: optional parameter. The end of line symbol, the default is the newline symbol \n.

The first row of the csv file is a header row for each column name.- [header ‘bool’]: optional parameter. The bool type can choose true or false.

  • [MAX_FILE_SIZE unsigned_number]: optional parameter. The maximum file size of the file is in KB. The default is 0.

Example

  1. -- Enable save_query_result
  2. mysql> set global save_query_result = on;
  3. -- Set the saving time to 24 hours
  4. mysql> set global query_result_timeout = 24;
  5. -- Set the maximum value of a single query result to 100M
  6. mysql> set global query_result_maxsize = 200;
  7. -- Create a table and insert datas
  8. mysql> create table t1 (a int);
  9. mysql> insert into t1 values(1);
  10. -- You can check the table structure to confirm that the inserted data is correct
  11. mysql> select a from t1;
  12. +------+
  13. | a |
  14. +------+
  15. | 1 |
  16. +------+
  17. 1 row in set (0.16 sec)
  18. -- Query the most recently executed query ID in the current session
  19. mysql> select last_query_id();
  20. +--------------------------------------+
  21. | last_query_id() |
  22. +--------------------------------------+
  23. | c187873e-c25d-11ed-aa5a-acde48001122 |
  24. +--------------------------------------+
  25. 1 row in set (0.12 sec)
  26. -- Get the query results for this query ID
  27. mysql> select * from result_scan('c187873e-c25d-11ed-aa5a-acde48001122') as t;
  28. +------+
  29. | a |
  30. +------+
  31. | 1 |
  32. +------+
  33. 1 row in set (0.01 sec)
  34. -- Check the metadata for this query ID
  35. mysql> select * from meta_scan('c187873e-c25d-11ed-aa5a-acde48001122') as t;
  36. +--------------------------------------+------------------+------------+---------+---------------------------------------------------------------------+---------------------+----------------------+--------+---------+---------------------+-----------+
  37. | query_id | statement | account_id | role_id | result_path | create_time | result_size | tables | user_id | expired_time | ColumnMap |
  38. +--------------------------------------+------------------+------------+---------+---------------------------------------------------------------------+---------------------+----------------------+--------+---------+---------------------+-----------+
  39. | c187873e-c25d-11ed-aa5a-acde48001122 | select a from t1 | 0 | 0 | SHARED:/query_result/sys_c187873e-c25d-11ed-aa5a-acde48001122_1.blk | 2023-03-14 19:45:45 | 0.000003814697265625 | t1 | 1 | 2023-03-15 19:45:45 | t1.a -> a |
  40. +--------------------------------------+------------------+------------+---------+---------------------------------------------------------------------+---------------------+----------------------+--------+---------+---------------------+-----------+
  41. 1 row in set (0.00 sec)
  42. -- Save query results locally
  43. MODUMP QUERY_RESULT c187873e-c25d-11ed-aa5a-acde48001122 INTO 'etl:your_local_path';

Constraints

MatrixOne only supports on saving the query results of SELECT and SHOW.