Skip to content

Commit cfb2984

Browse files
pgulutzanalexandra-marapatiencedaur
authored
Fixes gh-2206 Behavior changes in SQL (#2350)
Resolves #2295, #2296, #2298 Written by Peter Gulutzan Translated by Alexandra Mirzuitova, translation reviewed by Patience Daur Co-authored-by: Peter Gulutzan <[email protected]> Co-authored-by: Alexandra Mirzuitova <[email protected]> Co-authored-by: Patience Daur <[email protected]>
1 parent 0d5dae8 commit cfb2984

File tree

17 files changed

+1472
-759
lines changed

17 files changed

+1472
-759
lines changed

Diff for: doc/reference/reference_sql/data_type.spec

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ stack (
33
choice(
44
line(' BOOL '),
55
line(' BOOLEAN '),
6+
line(' DECIMAL '),
67
line(' DOUBLE '),
78
line(' INT '),
89
line(' INTEGER '),

Diff for: doc/reference/reference_sql/data_type.svg

+133-126
Loading

Diff for: doc/reference/reference_sql/sql-features.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ marked "Okay" will probably be balanced by tests which are unfairly marked "Fail
3838
| | | | columns (created from Lua) from FLOAT/DOUBLE/REAL ones |
3939
| | | | (created from SQL). |
4040
+------------+-----------------------------------------------+----------------------------------------------------------+---------------------------------------------------------+
41-
| E011-03 | DECIMAL and NUMERIC data types | ``CREATE TABLE td (s1 NUMERIC PRIMARY KEY);`` | Fail, DECIMAL and NUMERIC data types are not supported |
41+
| E011-03 | DECIMAL and NUMERIC data types | ``CREATE TABLE td (s1 NUMERIC PRIMARY KEY);`` | Fail, NUMERIC data types are not supported |
4242
| | | | and a number containing post-decimal digits will be |
4343
| | | | treated as approximate numeric. |
4444
+------------+-----------------------------------------------+----------------------------------------------------------+---------------------------------------------------------+
@@ -308,9 +308,9 @@ marked "Okay" will probably be balanced by tests which are unfairly marked "Fail
308308
| F031-03 | GRANT statement | | Fail. Tarantool doesn't support privileges except |
309309
| | | | via NoSQL. |
310310
+------------+-----------------------------------------------+----------------------------------------------------------+---------------------------------------------------------+
311-
| F031-04 | ALTER TABLE statement: add column | ``ALTER TABLE t7 ADD COLUMN t7_2 VARCHAR DEFAULT 'q';`` | Fail. Tarantool supports |
312-
| | | | :ref:`ALTER TABLE <sql_alter_table>` but not |
313-
| | | | this clause. |
311+
| F031-04 | ALTER TABLE statement: add column | ``ALTER TABLE t7 ADD COLUMN t7_2 VARCHAR(1) | Okay. Tarantool supports |
312+
| | | DEFAULT 'q';`` | :ref:`ALTER TABLE <sql_alter_table>` and support for |
313+
| | | | ADD COLUMN was added in Tarantool version 2.7. |
314314
+------------+-----------------------------------------------+----------------------------------------------------------+---------------------------------------------------------+
315315
| F031-13 | DROP TABLE statement: RESTRICT clause | ``DROP TABLE t20 RESTRICT;`` | Fail. Tarantool supports |
316316
| | | | :ref:`DROP TABLE <sql_drop_table>` but not this |
@@ -448,9 +448,9 @@ marked "Okay" will probably be balanced by tests which are unfairly marked "Fail
448448
| | | | name (not counted in the final score). |
449449
+------------+-----------------------------------------------+----------------------------------------------------------+---------------------------------------------------------+
450450

451-
Total number of items marked "Fail": 68
451+
Total number of items marked "Fail": 67
452452

453-
Total number of items marked "Okay": 78
453+
Total number of items marked "Okay": 79
454454

455455

456456

Diff for: doc/reference/reference_sql/sql_beginners_guide.rst

+31-31
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ we prefer to pick out specific items by their contents. In that spirit, this is
3232

3333
.. code-block:: none
3434
35-
modules
35+
MODULES
3636
3737
+-----------------+------+---------------------+
38-
| name | size | purpose |
39-
+-----------------|------|---------------------|
38+
| NAME | SIZE | PURPOSE |
39+
+-----------------+------+---------------------+
4040
| box | 1432 | Database Management |
4141
| clock | 188 | Seconds |
4242
| crypto | 4 | Cryptography |
@@ -165,8 +165,8 @@ A primary-key column automatically has a UNIQUE index.
165165

166166
data domain -- if a column is defined as having data type INTEGER, it is illegal to put a non-number into it.
167167
More generally, if a value doesn't correspond to the data type of the definition, it is illegal.
168-
However, some database management systems (DBMSs) are very forgiving and will try to
169-
make allowances for bad values rather than reject them; Tarantool is one of those DBMSs.
168+
Some database management systems (DBMSs) are very forgiving and will try to
169+
make allowances for bad values rather than reject them; Tarantool is a bit more strict than those DBMSs.
170170

171171
Now, here are other types of constraints ...
172172

@@ -216,7 +216,7 @@ By default searches in Tarantool's SQL use a binary collation. This will work:
216216
``INSERT INTO submodules`` |br|
217217
|nbsp| |nbsp| ``VALUES ('space', 'box', 10000, 'insert etc.');``
218218

219-
Now try to delete the new row from the modules table:
219+
Now try to delete the corresponding row from the modules table:
220220

221221
``DELETE FROM modules WHERE name = 'box';``
222222

@@ -352,9 +352,9 @@ but displayed as a table the result will look like
352352
.. code-block:: none
353353
354354
+----------------+------------------------+
355-
| double_size | concatenated_literals |
355+
| DOUBLE_SIZE | CONCATENATED_LITERALS |
356356
+----------------+------------------------+
357-
| 8| XY |
357+
| 8 | XY |
358358
+----------------+------------------------+
359359
360360
**Selecting with a select list with asterisk**
@@ -411,7 +411,7 @@ The result will look like this:
411411
.. code-block:: none
412412
413413
+-------------------+------------------------+--------------------+
414-
| submodules_name | modules_purpose | submodules_purpose |
414+
| SUBMODULES_NAME | MODULES_PURPOSE | SUBMODULES_PURPOSE |
415415
+-------------------+------------------------+--------------------+
416416
| space | Database Management | insert etc. |
417417
+-------------------+------------------------+--------------------+
@@ -437,11 +437,11 @@ That is legal. Usually it is not what you want, but it is a learning aid. The re
437437
438438
{ columns from modules table } { columns from submodules table }
439439
+--------+------+---------------------+-------+-------------+-------+-------------+
440-
| name | size | purpose | name | module_name | size | purpose |
440+
| NAME | SIZE | PURPOSE | NAME | MODULE_NAME | SIZE | PURPOSE |
441441
+--------+------+---------------------+-------+-------------+-------+-------------+
442442
| box | 1432 | Database Management | space | box | 10000 | insert etc. |
443-
| clock | 188 | Seconds | space | box | 10000 | insert etc. |
444-
| crypto | 4 | Cryptography | space | box | 10000 | insert etc. |
443+
| clock | 188 | Seconds | space | box | 10000 | insert etc. |
444+
| crypto | 4 | Cryptography | space | box | 10000 | insert etc. |
445445
+--------+------+---------------------+-------+-------------+-------+-------------+
446446
447447
It is not an error. The meaning of this type of join is "combine every row in table-1 with every row in table-2".
@@ -469,12 +469,12 @@ The result will be:
469469
.. code-block:: none
470470
471471
+----------+-----------+------------+--------+---------+-------+-------------+
472-
| modules_ | modules_ | modules_ | name | module_ | size | purpose |
473-
| name | size | purpose | | name | | |
474-
+----------+-----------+--------- --+--------+---------+-------+-------------|
475-
| box | 1432 | Database | space | box | 10000 | insert etc. |
472+
| MODULES_ | MODULES_ | MODULES_ | NAME | MODULE_ | SIZE | PURPOSE |
473+
| NAME | SIZE | PURPOSE | | NAME | | |
474+
+----------+-----------+--------- --+--------+---------+-------+-------------+
475+
| box | 1432 | Database | space | box | 10000 | insert etc. |
476476
| | | Management | | | | |
477-
+----------+-----------+------------+--------+---------+-------+-------------|
477+
+----------+-----------+------------+--------+---------+-------+-------------+
478478
479479
In other words, you can specify a Cartesian join in the FROM clause,
480480
then you can filter out the irrelevant rows in the WHERE clause,
@@ -556,11 +556,11 @@ which returns:
556556
557557
{ columns from modules table } { columns from submodules table }
558558
+--------+------+---------------------+-------+-------------+-------+-------------+
559-
| name | size | purpose | name | module_name | size | purpose |
559+
| NAME | SIZE | PURPOSE | NAME | MODULE_NAME | SIZE | PURPOSE |
560560
+--------+------+---------------------+-------+-------------+-------+-------------+
561561
| box | 1432 | Database Management | space | box | 10000 | insert etc. |
562-
| clock | 188 | Seconds | NULL | NULL | NULL | NULL |
563-
| crypto | 4 | Cryptography | NULL | NULL | NULL | NULL |
562+
| clock | 188 | Seconds | NULL | NULL | NULL | NULL |
563+
| crypto | 4 | Cryptography | NULL | NULL | NULL | NULL |
564564
+--------+------+---------------------+-------+-------------+-------+-------------+
565565
566566
Thus, for the submodules of the clock module and the submodules of the crypto
@@ -585,11 +585,11 @@ Remember that our modules table looks like this:
585585

586586
.. code-block:: none
587587
588-
modules
588+
MODULES
589589
590590
+-----------------+------+---------------------+
591-
| name | size | purpose |
592-
+-----------------|------|---------------------|
591+
| NAME | SIZE | PURPOSE |
592+
+-----------------+------+---------------------+
593593
| box | 1432 | Database Management |
594594
| clock | 188 | Seconds |
595595
| crypto | 4 | Cryptography |
@@ -598,7 +598,7 @@ Remember that our modules table looks like this:
598598
599599
Suppose that we do not want to know all the individual size values,
600600
we just want to know about their aggregation, that is, take the attributes of the collection.
601-
SQL allows five aggregation functions: AVG (average), SUM, MIN (minimum), MAX (maximum), and COUNT.
601+
SQL allows aggregation functions including: AVG (average), SUM, MIN (minimum), MAX (maximum), and COUNT.
602602
For example
603603

604604
``SELECT AVG(size), SUM(size), MIN(size), MAX(size), COUNT(size) FROM modules;``
@@ -607,11 +607,11 @@ The result will look like this:
607607

608608
.. code-block:: none
609609
610-
+--------------+-----------+-----------+-----------+-----------+
611-
| COLUMN_1 | COLUMN_2 | COLUMN_3 | COLUMN_4 | COLUMN_5 |
612-
+--------------+-----------+-----------+-----------+-----------|
613-
| 5.413333E+02 | 1624 | 4 | 1432 | 3 |
614-
+--------------+-----------+-----------+-----------+-----------+
610+
+-----------+-----------+-----------+-----------+-----------+
611+
| COLUMN_1 | COLUMN_2 | COLUMN_3 | COLUMN_4 | COLUMN_5 |
612+
+-----------+-----------+-----------+-----------+-----------|
613+
| 541 | 1624 | 4 | 1432 | 3 |
614+
+-----------+-----------+-----------+-----------+-----------+
615615
616616
Suppose that we want aggregations, but aggregations of rows that have some common characteristic.
617617
Supposing further, we want to divide the rows into two groups, the ones whose names
@@ -630,10 +630,10 @@ The result will look like this:
630630
631631
+------------+--------------+-----------+-----------+-----------+-------------+
632632
| COLUMN_1 | COLUMN_2 | COLUMN_3 | COLUMN_4 | COLUMN_5 | COLUMN_6 |
633-
+------------+--------------+-----------+-----------+-----------|-------------|
633+
+------------+--------------+-----------+-----------+-----------+-------------+
634634
| b | 1432 | 1432 | 1432 | 1432 | 1 |
635635
| c | 96 | 192 | 4 | 188 | 2 |
636-
+------------+--------------+-----------+-----------+-----------|-------------+
636+
+------------+--------------+-----------+-----------+-----------+-------------+
637637
638638
639639
**Select with common table expression**

Diff for: doc/reference/reference_sql/sql_plus_lua.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ If there were no Lua functions, we would have to treat it as a VARBINARY
347347
and look for ``POSITION(X'A476696577C3',"flags") > 0`` (A4 is a MsgPack signal
348348
that a 4-byte string follows, 76696577 is UTF8 encoding for 'view',
349349
C3 is a MsgPack code meaning true).
350+
In any case, starting with Tarantool version 2.10, POSITION() does not work on VARBINARY operands.
350351
But we have a more sophisticated way, we can create a function that
351352
returns true if ``"flags".view`` is true.
352353
So our way of making the function looks like this:
@@ -634,7 +635,7 @@ _COLUMNS view
634635
********************************************************************************
635636

636637
This is also an example of how one can use :ref:`recursive views <sql_with>` to make temporary tables
637-
with multiple rows for each tuple in the original ``"_vtable"`` space.
638+
with multiple rows for each tuple in the original ``"_vspace"`` space.
638639
It requires a global variable, _G.box.FORMATS, as a temporary static variable.
639640

640641
Warning: Use this code only with Tarantool version 2.3.2 or later.

0 commit comments

Comments
 (0)