How does TiDB distinguish whether an SQL query is OLTP or OLAP?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: TiDB如何区分一条SQL是OLTP或者OLAP?

| username: alfred

【TiDB Usage Environment】Production Environment or Test Environment or POC
【TiDB Version】
【Encountered Problem】
【Reproduction Path】What operations were performed that led to the problem
【Problem Phenomenon and Impact】

【Attachments】 Relevant logs and monitoring (https://metricstool.pingcap.com/)


For questions related to performance optimization or troubleshooting, please download and run the script. Please select all and copy-paste the terminal output results for upload.

| username: forever | Original post link

This specifically depends on the business. What TiDB can do is also cooperate with TiFlash. For cost estimation, if there are very few columns in the query and calculation, the cost will be lower if it goes through TiFlash, and it will use columnar storage for the query.

| username: HHHHHHULK | Original post link

After creating a table with TiFlash replicas, the TiDB optimizer will automatically estimate the cost and decide whether to use the TiFlash replica.

To ensure optimal performance, make sure the statistics are accurate. If the statistics are accurate but the execution plan still does not use the more efficient TiFlash, you can manually specify a hint or reduce the tidb_opt_seek_factor parameter to make the optimizer more inclined to choose TiFlash.

| username: ti-tiger | Original post link

The TiDB optimizer will automatically choose whether to use the TiFlash replica based on cost estimation, or it can be manually enforced by the business to use a specified TiFlash replica for one or several tables. It should not be distinguishable from the SQL itself.

| username: alfred | Original post link

Indeed, it is very difficult to distinguish SQL itself.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.