From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp46.i.mail.ru (smtp46.i.mail.ru [94.100.177.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2773F469719 for ; Wed, 18 Mar 2020 00:00:38 +0300 (MSK) From: Chris Sosnin Message-Id: <892E6B07-11CA-4A55-BC55-08B9E34F6C27@tarantool.org> Content-Type: multipart/alternative; boundary="Apple-Mail=_371537D0-ACAB-444F-A8DE-2E0DA807A23C" Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Date: Wed, 18 Mar 2020 00:00:36 +0300 In-Reply-To: <20200317201232.GA4294@tarantool.org> References: <36341694915f89597f2ac938077d0d10bcad0448.1581940900.git.k.sosnin@tarantool.org> <20200316170212.GH14628@tarantool.org> <6B7EB5E1-B936-46F4-AB4F-28EEDB72408A@tarantool.org> <20200317201232.GA4294@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH 4/4] sql: provide a user friendly frontend for accessing session settings List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Nikita Pettik Cc: tarantool-patches@dev.tarantool.org --Apple-Mail=_371537D0-ACAB-444F-A8DE-2E0DA807A23C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Thank you for your answers! > On 17 Mar 2020, at 23:12, Nikita Pettik = wrote: >=20 > On 17 Mar 20:26, Chris Sosnin wrote: >>=20 >>=20 >>> On 16 Mar 2020, at 20:02, Nikita Pettik = wrote: >>>=20 >>> On 17 Feb 15:12, Chris Sosnin wrote: >>>> Currently if a user wants to change session setting with sql, he = has >>>> to execute non-obvious query, thus, we introduce a more native way = to >>>> do this. >>>=20 >>> It is not about non-obvious queries, but it is all about = documentation: >>> the better feature is described, the clearer its usage turns out to = be >>> for user. >>=20 >> Should I change the commit message? I though this patchset is about = simplifying >> the way session settings are updated? >=20 > I would say: >=20 > Currently if a user wants to change session settings via SQL, one has > to execute UPDATE query like: > [[UPDATE "_session_settings" SET "value" =3D true WHERE "name" =3D = 'name']] > However, direct access to system spaces isn't considered to be good = practice. > To avoid that and a bit simplify user's life, we introduce SQL = shortcut command > SET with following syntax: SET =3D . = is > supposed to be name of setting (note that it is uppercased as any = other > non-quoted indentifiers in SQL) and - value of corresponding = setting to > be set; should be either literal or binding marker. Also it is = worth > noting that SET doesn't provide any implicit casts, so must be = of the > type corresponding to the setting being updated.=20 >=20 > Example: > ... >=20 > ^ It is up to you. >=20 >>>=20 >>>> Closes #4711 >>>>=20 >>>> @TarantoolBot document >>>> Title: API for accessing _session_settings space. >>>> There are two ways of updating values of session settings: >>>> via Lua and SQL. >>>>=20 >>>> SQL: >>>> Instead of typing long UPDATE query one can use the SET statement: >>>> `box.execute([[SET "" =3D ]])`. >>>> Note, that this query is case sensitive so the name must be quoted. >>>>=20 >>>> Example: >>>> ``` >>>> tarantool> box.execute([[set "sql_default_engine" =3D 'memtx']]) >>>> --- >>>> - row_count: 1 >>>> ... >>>>=20 >>>> tarantool> box.execute([[set "sql_defer_foreign_keys" =3D true]]) >>>=20 >>> Why didn't you consider show/get command to retrieve setting value? >>> Otherwise, you simplify way to set session local options, but = doesn't >>> provide the same way to extract current values. >>=20 >> SELECT * FROM =E2=80=9C_session_settings=E2=80=9D is simple enough, = isn=E2=80=99t it? >=20 > In this case you'll get list of all settings. To get specific one > we should use this query: >=20 > SELECT value FROM "_session_settings" WHERE "name" =3D 'xxx' >=20 > I do not insist on implementing GET/SHOW SQL syntax now tho. >=20 >>>> diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h >>>> index d1fcf4761..3ffae5970 100644 >>>> --- a/src/box/sql/sqlInt.h >>>> +++ b/src/box/sql/sqlInt.h >>>> @@ -4510,4 +4510,15 @@ int >>>> sql_fieldno_by_name(struct Parse *parse_context, struct Expr = *field_name, >>>> uint32_t *fieldno); >>>>=20 >>>> diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c >>>> index 620d74e66..c81486fa6 100644 >>>> --- a/src/box/sql/vdbe.c >>>> +++ b/src/box/sql/vdbe.c >>>> @@ -55,6 +55,7 @@ >>>> #include "box/schema.h" >>>> #include "box/space.h" >>>> #include "box/sequence.h" >>>> +#include "box/session_settings.h" >>>>=20 >>>> /* >>>> * Invoke this macro on memory cells just prior to changing the >>>> @@ -5248,6 +5249,55 @@ case OP_IncMaxid: { >>>> break; >>>> } >>>>=20 >>>> +/* Opcode: Set P1 P2 * * * >>>> + * >>>> + * Set the new value of the session setting. P1 is the id of the >>>> + * setting in the session_settings array, P2 is the register >>>> + * holding a value. >>>> + */ >>>> +case OP_Set: { >>>=20 >>> Please, use more specific opcode name. Like OP_SettingSet. >>=20 >> Didn=E2=80=99t we accept =E2=80=99set=E2=80=99 syntax? >=20 > SET is okay, but I don't mind SET SETTING as well. OP_Set is too = general > name - SET keyword is also part of UPDATE syntax, so it may confuse = other > developers. Except for this nit patch LGTM. I don=E2=80=99t mind this changes, I will work on them tomorrow. --Apple-Mail=_371537D0-ACAB-444F-A8DE-2E0DA807A23C Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Thank= you for your answers!

On 17 Mar 2020, at 23:12, = Nikita Pettik <korablev@tarantool.org> wrote:

On 17 Mar 20:26, Chris Sosnin = wrote:


On 16 Mar = 2020, at 20:02, Nikita Pettik <korablev@tarantool.org> wrote:

On 17 Feb 15:12, Chris Sosnin wrote:
Currently if a user wants to change session = setting with sql, he has
to execute non-obvious query, = thus, we introduce a more native way to
do this.

It is not about non-obvious = queries, but it is all about documentation:
the better = feature is described, the clearer its usage turns out to be
for user.

Should I = change the commit message? I though this patchset is about = simplifying
the way session settings are updated?

I would say:

Currently if a user wants to change session settings via SQL, = one has
to execute = UPDATE query like:
[[UPDATE "_session_settings" SET "value" =3D true WHERE = "name" =3D 'name']]
However, direct access to system spaces isn't considered to = be good practice.
To avoid that and a bit simplify user's life, we introduce = SQL shortcut command
SET with following syntax: SET <setting_name> =3D = <value>. <setting_name> is
supposed to be name of setting (note that it is uppercased as = any other
non-quoted = indentifiers in SQL) and <value> - value of corresponding setting = to
be set; = <value> should be either literal or binding marker. Also it is = worth
noting that = SET doesn't provide any implicit casts, so <value> must be of = the
type = corresponding to the setting being updated. 

Example:
...

^ It is up to you.


Closes #4711

@TarantoolBot document
Title: API for accessing = _session_settings space.
There are two ways of updating = values of session settings:
via Lua and SQL.

SQL:
Instead of typing long = UPDATE query one can use the SET statement:
`box.execute([[SET "<setting_name>" =3D = <new_value>]])`.
Note, that this query is case = sensitive so the name must be quoted.

Example:
```
tarantool> = box.execute([[set "sql_default_engine" =3D 'memtx']])
---- row_count: 1
...

tarantool> box.execute([[set "sql_defer_foreign_keys" =3D = true]])

Why didn't you = consider show/get command to retrieve setting value?
Otherwise, you simplify way to set session local options, but = doesn't
provide the same way to extract current values.

SELECT * FROM = =E2=80=9C_session_settings=E2=80=9D is simple enough, isn=E2=80=99t = it?

In this case you'll get list of all settings. To get specific = one
we should use = this query:

SELECT value = FROM "_session_settings" WHERE "name" =3D 'xxx'

I do not insist on implementing = GET/SHOW SQL syntax now tho.

diff --git = a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index = d1fcf4761..3ffae5970 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -4510,4 +4510,15 = @@ int
sql_fieldno_by_name(struct Parse *parse_context, = struct Expr *field_name,
    uint32_t = *fieldno);

diff --git a/src/box/sql/vdbe.c = b/src/box/sql/vdbe.c
index 620d74e66..c81486fa6 100644
--- a/src/box/sql/vdbe.c
+++ = b/src/box/sql/vdbe.c
@@ -55,6 +55,7 @@
#include "box/schema.h"
#include = "box/space.h"
#include "box/sequence.h"
+#include "box/session_settings.h"

/*
* Invoke this macro on memory cells just = prior to changing the
@@ -5248,6 +5249,55 @@ case = OP_IncMaxid: {
break;
}

+/* Opcode: Set P1 P2 * * *
+ = *
+ * Set the new value of the session setting. P1 is the = id of the
+ * setting in the session_settings array, P2 is = the register
+ * holding a value.
+ */
+case OP_Set: {

Please, use more specific opcode name. Like OP_SettingSet.

Didn=E2=80=99t we accept = =E2=80=99set=E2=80=99 syntax?

SET is okay, but I don't mind = SET SETTING as well. OP_Set is too general
name - SET keyword is also part of UPDATE syntax, so it may = confuse other
developers. = Except for this nit patch LGTM.

I don=E2=80=99t mind this changes, I will work on = them tomorrow.

= --Apple-Mail=_371537D0-ACAB-444F-A8DE-2E0DA807A23C--