Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a DBMS (MySQL, SQL Server….) interpreted or compiled?

Tags:

database

mysql

I mean, in the terms of the SQL queries, Are they compiled or interpreted in a low level?. How it works internally, It is a SQL statement interpreted or compiled?.

like image 732
Felix Avatar asked Nov 02 '10 03:11

Felix


People also ask

Is SQL compiled or interpreted?

SQL is a fourth-generation language, meaning it is a scripting language that does not require compiling to run. Like most fourth-generation languages, SQL requires an interpreter that translates rather than compiles code. As with all languages, SQL has rules for issuing commands and queries.

Is SQL Server a compiler?

This article mentioned four popular SQL online compilers that allow developers to write and test SQL queries using the most popular database engine compilers such as SQL Server, Oracle, MySQL, and PostgreSQL.

Is MySQL an interpreter?

The MySQL command interpreter is commonly used to create databases and tables in web database applications and to test queries.

What is MySQL in DBMS?

MySQL is an Oracle-backed open source relational database management system (RDBMS) based on Structured Query Language (SQL).


1 Answers

It's typically working like this:

    SQL String ---[Optimizer]---> Execution Plan ---[Execution]---> Result

I personally like to see the optimizer (query planner) as something very similar to a compiler. It's transforming the SQL statement into something that is more easily executable. However, it's not nativity executable on the chip. This "compilation" is rather expensive--just like compiling C++ code. That's the part where different execution variants are evaluated; the join order, which index to use, and so on. It's a good practice to avoid this whenever possible by using bind parameters.

The execution plan is then taken up for execution by the database. However, the strategy is already fixed. the execution is just doing it. This part is kind of interpreting the execution plan, not the SQL.

After all, it is, somehow, similar to Java or .NET where the compilation turns the source code into a binary form that can be interpreted more easily. If we ignore JIT for this argument, the execution of a Java program is interpreting this meta-code.


I have used this way to explain the benefit of using bind parameters for (Oracle) performance in my free eBook "Use The Index, Luke".

like image 86
Markus Winand Avatar answered Sep 18 '22 01:09

Markus Winand