MemCP now executed its first SQL Query:
MySQL [(none)]> select 1+2 AS x; +------+ | x | +------+ | 3 | +------+ 1 row in set (0,000 sec)
As you can see, MemCP uses the MySQL protocol to communicate with its clients. There is also a REST endpoint but the REST endpoint is more suited for custom REST APIs (microservices and such) that want to run inside the same memory space as the database.
SQL compilation in MemCP works in two stages: Parse and Build Queryplan.
During the parse phase, a string called „SQL Query“ is transformed into multiple lists:
- List of SELECT fields together with their column names and their expressions (an expression is a data structure that describes how to compute a value)
- List of FROM tables with their table aliases as well as their table names (or subqueries)
- WHERE, GROUP, HAVING, ORDER BY, LIMIT clauses and so on
Then, there is a plan to flatten down any subqueries into a single FROM clause (according to this paper: https://cs.emis.de/LNI/Proceedings/Proceedings241/383.pdf)
After that, the function
- The join order
- When to calculate what
- Which conditions have to be evaluated when
- The exact nesting of
(scan)calls (see https://launix.de/launix/accessing-memcp-via-scheme/)
- The innermost loop will contain a call to
After that is done, the query can be executed.
Result lines are provided as records that are passed through the MySQL protocol or in case of the REST API printed as a stream of JSON lines.