SQL 解析查询是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25454585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 02:30:57  来源:igfitidea点击:

What does parsing a query mean?

sqlparsingquery-parser

提问by user3239652

Most relational databases handles a JDBC / SQL query in four steps:

大多数关系数据库通过四个步骤处理 JDBC/SQL 查询:

  1. Parse the incoming SQL query
  2. Compile the SQL query
  3. Plan/optimize the data acquisition path
  4. Execute the optimized query / acquire and return data
  1. 解析传入的 SQL 查询
  2. 编译 SQL 查询
  3. 规划/优化数据采集路径
  4. 执行优化的查询/获取和返回数据

I want to know what does "parse the incoming query" really mean? And what does "plan/optimize data acquisition path" mean?

我想知道“解析传入查询”的真正含义是什么?“规划/优化数据采集路径”是什么意思?

回答by wallyk

  1. Parsing means examining the characters input and recognizing it as a command or statement by looking through the characters for keywords and identifiers, ignoring comments, arranging quoted portions as string constants, and matching the overall structure to the language syntax making sense of it all.

  2. Plan/optimize means figure out the best way (of all the possible ways) to determine the result, usually with respect to execution time. It could also mean minimizing the number of locks needed. Maybe some parts of the query can be ignored (where ... and 1 == 1) or a table doesn't need to be accessed at all, etc.

  1. 解析意味着检查输入的字符并将其识别为命令或语句,方法是通过查看关键字和标识符的字符、忽略注释、将引用部分安排为字符串常量,以及将整体结构与语言语法相匹配,从而理解这一切。

  2. 计划/优化意味着找出确定结果的最佳方法(所有可能的方法),通常与执行时间有关。这也可能意味着最小化所需的锁数量。也许可以忽略查询的某些部分 ( where ... and 1 == 1) 或者根本不需要访问表等。

回答by Ganesh_Devlekar

parsing is one of the Process of compilation.

解析是编译的过程之一。

Phases of a Compiler:

编译器的阶段:

enter image description here

在此处输入图片说明

Source: Phases of Compiler

资料来源:编译器阶段

回答by uncoder

1) Parsing: syntactic analysis of the query according to the SQL grammar rules, etc. and attempting to "tokenize" the query into the elementary parts form.

1)解析:根据SQL语法规则等对查询进行句法分析,并尝试将查询“标记化”为基本部分形式。

2) Planning/optimization: at that stage the SQL engine tries to evaluate what the best way to execute your query would be. It tries to take advantage of existing indexes, clusters and table relationships; find ways around full table scans, utilize caching effectively by avoiding repeated data reads, and so forth.

2) 规划/优化:在那个阶段,SQL 引擎会尝试评估执行查询的最佳方式。它试图利用现有的索引、集群和表关系;找到绕过全表扫描的方法,通过避免重复读取数据来有效利用缓存,等等。