From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 0DB46264C5 for ; Mon, 23 Jul 2018 12:20:20 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id opxqY5gF5q-c for ; Mon, 23 Jul 2018 12:20:19 -0400 (EDT) Received: from smtp40.i.mail.ru (smtp40.i.mail.ru [94.100.177.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 69161222FB for ; Mon, 23 Jul 2018 12:20:19 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [tarantool-patches] Re: [PATCH v1 1/1] sql: prevent executing crossengine sql From: "n.pettik" In-Reply-To: <26691970-9406-1cd2-e2ea-3e78b4d7b145@tarantool.org> Date: Mon, 23 Jul 2018 19:20:16 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <6134a0afdcfba13ca289e2d42fdd529a2787070a.1532094680.git.kshcherbatov@tarantool.org> <50ac96b7-d395-f528-f66b-c10847e54670@tarantool.org> <812d64bf-a5a8-805d-d353-32f6733a41b9@tarantool.org> <26691970-9406-1cd2-e2ea-3e78b4d7b145@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Kirill Shcherbatov , Vladislav Shpilevoy >> struct iterator *it =3D = index_create_iterator(*pCur->space->index, >> ITER_ALL, nil_key, >> 0 /* part_count */); >> @@ -1134,12 +1135,26 @@ cursor_seek(BtCursor *pCur, int *pRes) >> return SQL_TARANTOOL_ITERATOR_FAIL; >> } >> + struct space *space =3D pCur->space; >> + struct txn *txn =3D NULL;> + >> + assert(space->def->id !=3D 0 || space_is_memtx(space)); >> + if (space->def->id !=3D 0 &&> + space->def->id !=3D = BOX_SQL_STAT4_ID && >> + space->def->id !=3D BOX_SQL_STAT1_ID) { >=20 > 2. I strongly do not like these 3 checks. >=20 > * space->id =3D=3D 0 can be skipped, since begin_ro_stmt needs > only space engine. >=20 > * id !=3D stat4/1 is a huge crutch that should be removed. The > later will be dilapidated by any stat or tx manager change. > I guess it is because of ANALYZE that scans spaces and then > updates _stat1/4. But I can not understand, why it can not > firstly read the samples from user spaces, commit ro, and > secondly insert the samples into stats in another transaction. > Besides, I believe, that user spaces and analyze ones should > not be in a single transaction ever as former are actually > system ones and should not be mixed with user spaces. > Nikita, I appeal to you for onlooking. Is it possible to > split ANALYZE in two transactions? How could Kirill do it? > Besides there is another option, but IMHO it could seem even > more flawed. Why do you think so? Actually, I can=E2=80=99t come up with better = solution: when we start executing OP_AnalysisLoad we always start transaction (member that issue with gathering statistics on region to make it = consistent? See sql_analysis_load()). Mb we always can avoid calling txn_begin_ro_stmt() on system spaces? Quite similar to this issue might be CREATE TABLE AS SELECT when it will be implemented. However, in this case we still can avoid mixing user and system spaces within one transaction: INSERT TO _SPACE/_INDEX etc SELECT FROM source INSERT TO ephemeral START TRANSACTION SELECT FROM ephemeral INSERT TO destination COMMIT TRANSACTION > We could introduce a new opcode or add an option > for OP_Seek like 'is_atomic' that will trigger ro stmt start. > For spaces like analyze and ephemeral ones we could set this > option in True thereby "allowing" cross-engine transactions > for internal usage when we do not need read-view and other tx > manager facilities. >=20 >=20 >> + if (txn_begin_ro_stmt(space, &txn) !=3D 0) >> + return SQL_TARANTOOL_ERROR; >> + } >> struct iterator *it =3D index_create_iterator(pCur->index, = pCur->iter_type, >> key, part_count); >> if (it =3D=3D NULL) { >> + if (txn !=3D NULL) >> + txn_rollback_stmt(); >> pCur->eState =3D CURSOR_INVALID; >> return SQL_TARANTOOL_ITERATOR_FAIL; >> } >> + if (txn !=3D NULL) >> + txn_commit_ro_stmt(txn); >> pCur->iter =3D it; >> pCur->eState =3D CURSOR_VALID; >> =20 >=20