📜 ⬆️ ⬇️

MySQL is NoSQL!

As you know, MySQL has two drawbacks *. First, the query language is SQL. This is corrected with the help of HandlerSocket, about which there have already been articles on the site. Secondly, it does not have a built-in javascript.

* - in fact, this is a joke. MySQL has two shortcomings, but they are completely different from what I wrote. and the absence of javascript is, of course, not a flaw. However, if we imagine that MySQL has no SQL interface at all, then we will have to compare it (as a NoSQL solution) with MongoDB, in particular, in which there is a javascript interpreter.

So, I started working on the second direction and have already received some results:


Currently you can do the following:
  mysql> select execute_js ("10 + 30") as r;
 + ---- +
 |  r |
 + ---- +
 |  40 |
 + ---- +
 1 row in set (0.08 sec)

They passed the expression, it ran and returned the result.
')
  mysql> select execute_js ("function f (x) {return x + 20;}; f (30)") as r;
 + ---- +
 |  r |
 + ---- +
 |  50 |
 + ---- +
 1 row in set (0.08 sec)

Similarly: they made a function, called it, returned the result from the function.

  mysql> select execute_js ("function func (x) {return x * 1 + 10;}", "func", "20") as r;  # see description below
 + ---- +
 |  r |
 + ---- +
 |  30 |
 + ---- +
 1 row in set (0.08 sec)

 mysql> select execute_js ("require ('/ tmp / func.js')", "func", "30") as r;  # see description below
 + ---- +
 |  r |
 + ---- +
 |  40 |
 + ---- +
 1 row in set (0.08 sec)


Here we (1) initialize a global object with something, (2) specify the name of the function to be called, (3 - ...) call it with these parameters. Why do you need it?

  mysql> select execute_js ("require ('/ tmp / func.js');", "func", CONCAT (num.i, "")) as r from num;
 + ---- +
 |  r |
 + ---- +
 |  11 |
 |  12 |
 |  13 |
 |  13 |
 |  15 |
 |  16 |
 |  16 |
 |  16 |
 |  19 |
 |  19 |
 |  19 |
 |  20 |
 + ---- +
 12 rows in set (0.08 sec)

That's why: we create a global object once, we create a function there once, but we call the function several times and with different parameters.
As many have already guessed, 0.08 seconds is the initialization time of the V8. Naturally, it is possible and necessary to initialize V8 not once for each request, but once for each stream, or somehow even more cunning.

view source

TODO LIST:
1. error handling / stability. Now with syntax errors everything falls.
2. less often initialize the V8 interpreter
3. mysql_find - NoSQL interface to MySQL database contents. here I while understand with locks and transactions. for example, should all operations be performed within a single transaction, or one operation — a single transaction? or give a read-only interface altogether?

I will be glad to comments and suggestions.

Source: https://habr.com/ru/post/123311/


All Articles