Query plan

SHOW PLAN is an SQL statement that displays the execution plan of the previous SELECT statement. The plan gets generated and stored during the actual execution, so profiling must be enabled in the current session before running that statement. That can be done with a SET profiling=1 statement.

To view query execution plan in JSON queries, add "profile":true to the query. The result appears as a profile property in the result set.

Note, there are 2 things returned in the SQL mode:

  • transformed_tree which shows the full-text query decomposition
  • enabled_indexes which shows information about effective secondary indexes
  • SQL
  • JSON

SQL JSON

  1. set profiling=1;
  2. select * from hn_small where match('dog|cat') limit 0;
  3. show plan;
  1. POST /search
  2. {
  3. "index": "hn_small",
  4. "query": {"query_string": "dog|cat"},
  5. "_source": { "excludes":["*"] },
  6. "limit": 0,
  7. "profile":true
  8. }

Response

  1. *************************** 1. row ***************************
  2. Variable: transformed_tree
  3. Value: OR(
  4. AND(KEYWORD(dog, querypos=1)),
  5. AND(KEYWORD(cat, querypos=2)))
  6. *************************** 2. row ***************************
  7. Variable: enabled_indexes
  8. Value:
  9. 2 rows in set (0.00 sec)
  1. {
  2. "took": 0,
  3. "timed_out": false,
  4. "hits": {
  5. "total": 4453,
  6. "total_relation": "eq",
  7. "hits": []
  8. },
  9. "profile": {
  10. "query": {
  11. "type": "OR",
  12. "description": "OR( AND(KEYWORD(dog, querypos=1)), AND(KEYWORD(cat, querypos=2)))",
  13. "children": [
  14. {
  15. "type": "AND",
  16. "description": "AND(KEYWORD(dog, querypos=1))",
  17. "children": [
  18. {
  19. "type": "KEYWORD",
  20. "word": "dog",
  21. "querypos": 1
  22. }
  23. ]
  24. },
  25. {
  26. "type": "AND",
  27. "description": "AND(KEYWORD(cat, querypos=2))",
  28. "children": [
  29. {
  30. "type": "KEYWORD",
  31. "word": "cat",
  32. "querypos": 2
  33. }
  34. ]
  35. }
  36. ]
  37. }
  38. }
  39. }

In some cases the evaluated query tree can be rather different from the original one because of expansions and other transformations.

  • SQL
  • JSON

SQL JSON

  1. SET profiling=1;
  2. SELECT id FROM forum WHERE MATCH('@title way* @content hey') LIMIT 1;
  3. SHOW PLAN;
  1. POST /search
  2. {
  3. "index": "forum",
  4. "query": {"query_string": "@title way* @content hey"},
  5. "_source": { "excludes":["*"] },
  6. "limit": 1,
  7. "profile": true
  8. }

Response

  1. Query OK, 0 rows affected (0.00 sec)
  2. +--------+
  3. | id |
  4. +--------+
  5. | 711651 |
  6. +--------+
  7. 1 row in set (0.04 sec)
  8. +------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  9. | Variable | Value |
  10. +------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  11. | transformed_tree | AND(
  12. OR(
  13. OR(
  14. AND(fields=(title), KEYWORD(wayne, querypos=1, expanded)),
  15. OR(
  16. AND(fields=(title), KEYWORD(ways, querypos=1, expanded)),
  17. AND(fields=(title), KEYWORD(wayyy, querypos=1, expanded)))),
  18. AND(fields=(title), KEYWORD(way, querypos=1, expanded)),
  19. OR(fields=(title), KEYWORD(way*, querypos=1, expanded))),
  20. AND(fields=(content), KEYWORD(hey, querypos=2))) |
  21. +------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. 1 row in set (0.00 sec)
  1. {
  2. "took":33,
  3. "timed_out":false,
  4. "hits":
  5. {
  6. "total":105,
  7. "hits":
  8. [
  9. {
  10. "_id":"711651",
  11. "_score":2539,
  12. "_source":{}
  13. }
  14. ]
  15. },
  16. "profile":
  17. {
  18. "query":
  19. {
  20. "type":"AND",
  21. "description":"AND( OR( OR( AND(fields=(title), KEYWORD(wayne, querypos=1, expanded)), OR( AND(fields=(title), KEYWORD(ways, querypos=1, expanded)), AND(fields=(title), KEYWORD(wayyy, querypos=1, expanded)))), AND(fields=(title), KEYWORD(way, querypos=1, expanded)), OR(fields=(title), KEYWORD(way*, querypos=1, expanded))), AND(fields=(content), KEYWORD(hey, querypos=2)))",
  22. "children":
  23. [
  24. {
  25. "type":"OR",
  26. "description":"OR( OR( AND(fields=(title), KEYWORD(wayne, querypos=1, expanded)), OR( AND(fields=(title), KEYWORD(ways, querypos=1, expanded)), AND(fields=(title), KEYWORD(wayyy, querypos=1, expanded)))), AND(fields=(title), KEYWORD(way, querypos=1, expanded)), OR(fields=(title), KEYWORD(way*, querypos=1, expanded)))",
  27. "children":
  28. [
  29. {
  30. "type":"OR",
  31. "description":"OR( AND(fields=(title), KEYWORD(wayne, querypos=1, expanded)), OR( AND(fields=(title), KEYWORD(ways, querypos=1, expanded)), AND(fields=(title), KEYWORD(wayyy, querypos=1, expanded))))",
  32. "children":
  33. [
  34. {
  35. "type":"AND",
  36. "description":"AND(fields=(title), KEYWORD(wayne, querypos=1, expanded))",
  37. "fields":["title"],
  38. "max_field_pos":0,
  39. "children":
  40. [
  41. {
  42. "type":"KEYWORD",
  43. "word":"wayne",
  44. "querypos":1,
  45. "expanded":true
  46. }
  47. ]
  48. },
  49. {
  50. "type":"OR",
  51. "description":"OR( AND(fields=(title), KEYWORD(ways, querypos=1, expanded)), AND(fields=(title), KEYWORD(wayyy, querypos=1, expanded)))",
  52. "children":
  53. [
  54. {
  55. "type":"AND",
  56. "description":"AND(fields=(title), KEYWORD(ways, querypos=1, expanded))",
  57. "fields":["title"],
  58. "max_field_pos":0,
  59. "children":
  60. [
  61. {
  62. "type":"KEYWORD",
  63. "word":"ways",
  64. "querypos":1,
  65. "expanded":true
  66. }
  67. ]
  68. },
  69. {
  70. "type":"AND",
  71. "description":"AND(fields=(title), KEYWORD(wayyy, querypos=1, expanded))",
  72. "fields":["title"],
  73. "max_field_pos":0,
  74. "children":
  75. [
  76. {
  77. "type":"KEYWORD",
  78. "word":"wayyy",
  79. "querypos":1,
  80. "expanded":true
  81. }
  82. ]
  83. }
  84. ]
  85. }
  86. ]
  87. },
  88. {
  89. "type":"AND",
  90. "description":"AND(fields=(title), KEYWORD(way, querypos=1, expanded))",
  91. "fields":["title"],
  92. "max_field_pos":0,
  93. "children":
  94. [
  95. {
  96. "type":"KEYWORD",
  97. "word":"way",
  98. "querypos":1,
  99. "expanded":true
  100. }
  101. ]
  102. },
  103. {
  104. "type":"OR",
  105. "description":"OR(fields=(title), KEYWORD(way*, querypos=1, expanded))",
  106. "fields":["title"],
  107. "max_field_pos":0,
  108. "children":
  109. [
  110. {
  111. "type":"KEYWORD",
  112. "word":"way*",
  113. "querypos":1,
  114. "expanded":true
  115. }
  116. ]
  117. }
  118. ]
  119. },
  120. {
  121. "type":"AND",
  122. "description":"AND(fields=(content), KEYWORD(hey, querypos=2))",
  123. "fields":["content"],
  124. "max_field_pos":0,
  125. "children":
  126. [
  127. {
  128. "type":"KEYWORD",
  129. "word":"hey",
  130. "querypos":2
  131. }
  132. ]
  133. }
  134. ]
  135. }
  136. }
  137. }

See also EXPLAIN QUERY. It displays the execution tree of a full-text query without actually executing the query.

JSON result set notes

query property contains the transformed fulltext query tree. Each node contains:

  • type: node type. Can be AND, OR, PHRASE, KEYWORD etc.
  • description: query subtree for this node shown as a string (in SHOW PLAN format)
  • children: child nodes, if any
  • max_field_pos: maximum position within a field
  • word: transformed keyword. Keyword nodes only.
  • querypos: position of this keyword in a query. Keyword nodes only.
  • excluded: keyword excluded from query. Keyword nodes only.
  • expanded: keyword added by prefix expansion. Keyword nodes only.
  • field_start: keyword must occur at the very start of the field. Keyword nodes only.
  • field_end: keyword must occur at the very end of the field. Keyword nodes only.
  • boost: keyword IDF will be multiplied by this. Keyword nodes only.

Dot format for SHOW PLAN

SHOW PLAN format=dot allows to return the full-text query execution tree in hierarchical format suitable for visualization by existing tools, for example https://dreampuf.github.io/GraphvizOnline :

  1. MySQL [(none)]> show plan option format=dot\G
  2. *************************** 1. row ***************************
  3. Variable: transformed_tree
  4. Value: digraph "transformed_tree"
  5. {
  6. 0 [shape=record,style=filled,bgcolor="lightgrey" label="AND"]
  7. 0 -> 1
  8. 1 [shape=record,style=filled,bgcolor="lightgrey" label="AND"]
  9. 1 -> 2
  10. 2 [shape=record label="i | { querypos=1 }"]
  11. 0 -> 3
  12. 3 [shape=record,style=filled,bgcolor="lightgrey" label="AND"]
  13. 3 -> 4
  14. 4 [shape=record label="me | { querypos=2 }"]
  15. }

SHOW PLAN graphviz example

Table settings and status

SHOW TABLE STATUS

SHOW TABLE STATUS is an SQL statement that displays various per-table statistics.

The syntax is:

  1. SHOW TABLE index_name STATUS

Displayed statistics include:

  • index_type: for now that is one of disk, rt, percolate, template, and distributed.
  • indexed_documents and indexed_bytes: number of indexed documents and their text size in bytes, respectively.
  • field_tokens_XXX: sums of per-field lengths (in tokens) over the entire table (that is used internally in BM25A and BM25F functions for ranking purposes). Only available for tables built with index_field_lengths=1.
  • ram_bytes: total size (in bytes) of RAM-resident table portion.
  • disk_bytes: total size (in bytes) of all table files.
  • disk_mapped: total size of file mappings.
  • disk_mapped_cached: total size of file mappings actually cached in RAM.
  • disk_mapped_doclists and disk_mapped_cached_doclists: part of the total and cached mappings belonging to document lists.
  • disk_mapped_hitlists and disk_mapped_cached_hitlists: part of the total and cached mappings belonging to hit lists. Values for doclists and hitlists are shown separately since they’re usually huge (say, about 90% size of the whole table).
  • killed_documents and killed_rate: the first one indicates the number of deleted documents and the rate of deleted/indexed. Technically deletion of a document just means that the document gets suppressed in search output, but physically it still persists in a table and will be purged only after merging/optimizing the table.
  • ram_chunk: size of RAM chunk of real-time or percolate table.
  • ram_chunk_segments_count: RAM chunk internally consists of segments, usually there are no more than 32 of them. This line shows the current count.
  • disk_chunks: number of disk chunks of the real-time table.
  • mem_limit: actual value of rt_mem_limit for the table.
  • mem_limit_rate: the rate after which the ram chunk will be flushed as a disk chunk, e.g. if rt_mem_limit is 128M and the rate is 50%, a new disk chunk will be saved as soon as the ram chunk exceeds 64M.
  • ram_bytes_retired: represents size of garbage in RAM chunks (for example, deleted or replaced documents not yet finally wiped away).
  • tid and tid_saved: represent the state of saving the table (real-time or percolate only). tid gets increased with each change (transaction). tid_saved shows max tid of the state saved in a RAM chunk in <table>.ram file. When the numbers are different, some changes exist only in RAM and also backed by binlog (if enabled). Performing FLUSH TABLE or scheduling periodical flushing causes these changes to be saved. After flushing the binlog gets cleared, and the tid_saved represents the actual new state.
  • query_time_*: query execution time statistics of last 1 minute, 5 minutes, 15 minutes and total since server start; the data is encapsulated as a JSON object which includes the number of queries and min, max, avg, 95 and 99 percentile values.
  • found_rows_*: statistics of rows found by queries; provided for last 1 minute, 5 minutes, 15 minutes and total since server start; the data is encapsulated as a JSON object which includes the number of queries and min, max, avg, 95 and 99 percentile values.
  • SQL
  • PHP
  • Python
  • Javascript
  • Java

SQL PHP Python Javascript Java

  1. mysql> SHOW TABLE statistic STATUS;
  1. $index->status();
  1. utilsApi.sql('SHOW TABLE statistic STATUS')
  1. res = await utilsApi.sql('SHOW TABLE statistic STATUS');
  1. utilsApi.sql("SHOW TABLE statistic STATUS");

Response

  1. +-----------------------------+--------------------------------------------------------------------------+
  2. | Variable_name | Value |
  3. +-----------------------------+--------------------------------------------------------------------------+
  4. | index_type | rt |
  5. | indexed_documents | 146000 |
  6. | indexed_bytes | 149504000 |
  7. | ram_bytes | 87674788 |
  8. | disk_bytes | 1762811 |
  9. | disk_mapped | 794147 |
  10. | disk_mapped_cached | 802816 |
  11. | disk_mapped_doclists | 0 |
  12. | disk_mapped_cached_doclists | 0 |
  13. | disk_mapped_hitlists | 0 |
  14. | disk_mapped_cached_hitlists | 0 |
  15. | killed_documents | 0 |
  16. | killed_rate | 0.00% |
  17. | ram_chunk | 86865484 |
  18. | ram_chunk_segments_count | 24 |
  19. | disk_chunks | 1 |
  20. | mem_limit | 134217728 |
  21. | mem_limit_rate | 95.00% |
  22. | ram_bytes_retired | 0 |
  23. | tid | 0 |
  24. | tid_saved | 0 |
  25. | query_time_1min | {"queries":0, "avg":"-", "min":"-", "max":"-", "pct95":"-", "pct99":"-"} |
  26. | query_time_5min | {"queries":0, "avg":"-", "min":"-", "max":"-", "pct95":"-", "pct99":"-"} |
  27. | query_time_15min | {"queries":0, "avg":"-", "min":"-", "max":"-", "pct95":"-", "pct99":"-"} |
  28. | query_time_total | {"queries":0, "avg":"-", "min":"-", "max":"-", "pct95":"-", "pct99":"-"} |
  29. | found_rows_1min | {"queries":0, "avg":"-", "min":"-", "max":"-", "pct95":"-", "pct99":"-"} |
  30. | found_rows_5min | {"queries":0, "avg":"-", "min":"-", "max":"-", "pct95":"-", "pct99":"-"} |
  31. | found_rows_15min | {"queries":0, "avg":"-", "min":"-", "max":"-", "pct95":"-", "pct99":"-"} |
  32. | found_rows_total | {"queries":0, "avg":"-", "min":"-", "max":"-", "pct95":"-", "pct99":"-"} |
  33. +-----------------------------+--------------------------------------------------------------------------+
  34. 29 rows in set (0.00 sec)
  1. Array(
  2. [index_type] => rt
  3. [indexed_documents] => 3
  4. [indexed_bytes] => 0
  5. [ram_bytes] => 6678
  6. [disk_bytes] => 611
  7. [ram_chunk] => 990
  8. [ram_chunk_segments_count] => 2
  9. [mem_limit] => 134217728
  10. [ram_bytes_retired] => 0
  11. [tid] => 15
  12. [query_time_1min] => {"queries":1, "avg_sec":0.001, "min_sec":0.001, "max_sec":0.001, "pct95_sec":0.001, "pct99_sec":0.001}
  13. [query_time_5min] => {"queries":1, "avg_sec":0.001, "min_sec":0.001, "max_sec":0.001, "pct95_sec":0.001, "pct99_sec":0.001}
  14. [query_time_15min] => {"queries":1, "avg_sec":0.001, "min_sec":0.001, "max_sec":0.001, "pct95_sec":0.001, "pct99_sec":0.001}
  15. [query_time_total] => {"queries":1, "avg_sec":0.001, "min_sec":0.001, "max_sec":0.001, "pct95_sec":0.001, "pct99_sec":0.001}
  16. [found_rows_1min] => {"queries":1, "avg":3, "min":3, "max":3, "pct95":3, "pct99":3}
  17. [found_rows_5min] => {"queries":1, "avg":3, "min":3, "max":3, "pct95":3, "pct99":3}
  18. [found_rows_15min] => {"queries":1, "avg":3, "min":3, "max":3, "pct95":3, "pct99":3}
  19. [found_rows_total] => {"queries":1, "avg":3, "min":3, "max":3, "pct95":3, "pct99":3}
  20. )
  1. {u'columns': [{u'Key': {u'type': u'string'}},
  2. {u'Value': {u'type': u'string'}}],
  3. u'data': [
  4. {u'Key': u'index_type', u'Value': u'rt'}
  5. {u'Key': u'indexed_documents', u'Value': u'3'}
  6. {u'Key': u'indexed_bytes', u'Value': u'0'}
  7. {u'Key': u'ram_bytes', u'Value': u'6678'}
  8. {u'Key': u'disk_bytes', u'Value': u'611'}
  9. {u'Key': u'ram_chunk', u'Value': u'990'}
  10. {u'Key': u'ram_chunk_segments_count', u'Value': u'2'}
  11. {u'Key': u'mem_limit', u'Value': u'134217728'}
  12. {u'Key': u'ram_bytes_retired', u'Value': u'0'}
  13. {u'Key': u'tid', u'Value': u'15'}
  14. {u'Key': u'query_time_1min', u'Value': u'{"queries":1, "avg_sec":0.001, "min_sec":0.001, "max_sec":0.001, "pct95_sec":0.001, "pct99_sec":0.001}'}
  15. {u'Key': u'query_time_5min', u'Value': u'{"queries":1, "avg_sec":0.001, "min_sec":0.001, "max_sec":0.001, "pct95_sec":0.001, "pct99_sec":0.001}'}
  16. {u'Key': u'query_time_15min', u'Value': u'{"queries":1, "avg_sec":0.001, "min_sec":0.001, "max_sec":0.001, "pct95_sec":0.001, "pct99_sec":0.001}'}
  17. {u'Key': u'query_time_total', u'Value': u'{"queries":1, "avg_sec":0.001, "min_sec":0.001, "max_sec":0.001, "pct95_sec":0.001, "pct99_sec":0.001}'}
  18. {u'Key': u'found_rows_1min', u'Value': u'{"queries":1, "avg":3, "min":3, "max":3, "pct95":3, "pct99":3}'}
  19. {u'Key': u'found_rows_5min', u'Value': u'{"queries":1, "avg":3, "min":3, "max":3, "pct95":3, "pct99":3}'}
  20. {u'Key': u'found_rows_15min', u'Value': u'{"queries":1, "avg":3, "min":3, "max":3, "pct95":3, "pct99":3}'}
  21. {u'Key': u'found_rows_total', u'Value': u'{"queries":1, "avg":3, "min":3, "max":3, "pct95":3, "pct99":3}'}],
  22. u'error': u'',
  23. u'total': 0,
  24. u'warning': u''}
  1. {"columns": [{"Key": {"type": "string"}},
  2. {"Value": {"type": "string"}}],
  3. "data": [
  4. {"Key": "index_type", "Value": "rt"}
  5. {"Key": "indexed_documents", "Value": "3"}
  6. {"Key": "indexed_bytes", "Value": "0"}
  7. {"Key": "ram_bytes", "Value": "6678"}
  8. {"Key": "disk_bytes", "Value": "611"}
  9. {"Key": "ram_chunk", "Value": "990"}
  10. {"Key": "ram_chunk_segments_count", "Value": "2"}
  11. {"Key": "mem_limit", "Value": "134217728"}
  12. {"Key": "ram_bytes_retired", "Value": "0"}
  13. {"Key": "tid", "Value": "15"}
  14. {"Key": "query_time_1min", "Value": "{"queries":1, "avg_sec":0.001, "min_sec":0.001, "max_sec":0.001, "pct95_sec":0.001, "pct99_sec":0.001}"}
  15. {"Key": "query_time_5min", "Value": "{"queries":1, "avg_sec":0.001, "min_sec":0.001, "max_sec":0.001, "pct95_sec":0.001, "pct99_sec":0.001}"}
  16. {"Key": "query_time_15min", "Value": "{"queries":1, "avg_sec":0.001, "min_sec":0.001, "max_sec":0.001, "pct95_sec":0.001, "pct99_sec":0.001}"}
  17. {"Key": "query_time_total", "Value": "{"queries":1, "avg_sec":0.001, "min_sec":0.001, "max_sec":0.001, "pct95_sec":0.001, "pct99_sec":0.001}"}
  18. {"Key": "found_rows_1min", "Value": "{"queries":1, "avg":3, "min":3, "max":3, "pct95":3, "pct99":3}"}
  19. {"Key": "found_rows_5min", "Value": "{"queries":1, "avg":3, "min":3, "max":3, "pct95":3, "pct99":3}"}
  20. {"Key": "found_rows_15min", "Value": "{"queries":1, "avg":3, "min":3, "max":3, "pct95":3, "pct99":3}"}
  21. {"Key": "found_rows_total", "Value": "{"queries":1, "avg":3, "min":3, "max":3, "pct95":3, "pct99":3}"}],
  22. "error": "",
  23. "total": 0,
  24. "warning": ""}
  1. {columns=[{ Key : { type=string }},
  2. { Value : { type=string }}],
  3. data : [
  4. { Key=index_type, Value=rt}
  5. { Key=indexed_documents, Value=3}
  6. { Key=indexed_bytes, Value=0}
  7. { Key=ram_bytes, Value=6678}
  8. { Key=disk_bytes, Value=611}
  9. { Key=ram_chunk, Value=990}
  10. { Key=ram_chunk_segments_count, Value=2}
  11. { Key=mem_limit, Value=134217728}
  12. { Key=ram_bytes_retired, Value=0}
  13. { Key=tid, Value=15}
  14. { Key=query_time_1min, Value={queries:1, avg_sec:0.001, min_sec:0.001, max_sec:0.001, pct95_sec:0.001, pct99_sec:0.001}}
  15. { Key=query_time_5min, Value={queries:1, avg_sec:0.001, min_sec:0.001, max_sec:0.001, pct95_sec:0.001, pct99_sec:0.001}}
  16. { Key=query_time_15min, Value={queries:1, avg_sec:0.001, min_sec:0.001, max_sec:0.001, pct95_sec:0.001, pct99_sec:0.001}}
  17. { Key=query_time_total, Value={queries:1, avg_sec:0.001, min_sec:0.001, max_sec:0.001, pct95_sec:0.001, pct99_sec:0.001}}
  18. { Key=found_rows_1min, Value={queries:1, avg:3, min:3, max:3, pct95:3, pct99:3}}
  19. { Key=found_rows_5min, Value={queries:1, avg:3, min:3, max:3, pct95:3, pct99:3}}
  20. { Key=found_rows_15min, Value={queries:1, avg:3, min:3, max:3, pct95:3, pct99:3}}
  21. { Key=found_rows_total, Value={queries:1, avg:3, min:3, max:3, pct95:3, pct99:3}}],
  22. error= ,
  23. total=0,
  24. warning= }