Tarantool development patches archive
 help / color / mirror / Atom feed
From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Imeev Mergen <imeevma@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v1 1/2] sql: add OP_Error opcode in VDBE
Date: Wed, 26 Jun 2019 19:11:06 +0300	[thread overview]
Message-ID: <2CCDE513-7D85-41C7-A50D-3EDFA076EA8C@tarantool.org> (raw)
In-Reply-To: <7cbb598d41f2c5751538d22d5ea8c90e07fc8ebd.1561476468.git.imeevma@gmail.com>


> diff --git a/src/box/sql/build.c b/src/box/sql/build.c
> index 292168f..c75e1d8 100644
> --- a/src/box/sql/build.c
> +++ b/src/box/sql/build.c
> @@ -1066,14 +1066,21 @@ vdbe_emit_ck_constraint_create(struct Parse *parser,
> 		      sqlDbStrDup(db, ck_def->expr_str), P4_DYNAMIC);
> 	sqlVdbeAddOp3(v, OP_MakeRecord, ck_constraint_reg, 5,
> 		      ck_constraint_reg + 5);
> -	const char *error_msg =
> +	/* Check that there is no CHECK with such name. */
> +	const char *err =
> 		tt_sprintf(tnt_errcode_desc(ER_CONSTRAINT_EXISTS),
> 					    ck_def->name);
> -	if (vdbe_emit_halt_with_presence_test(parser, BOX_CK_CONSTRAINT_ID, 0,
> -					      ck_constraint_reg, 2,
> -					      ER_CONSTRAINT_EXISTS, error_msg,
> -					      false, OP_NoConflict) != 0)
> -		return;
> +	int cursor = parser->nTab++;
> +	vdbe_emit_open_cursor(parser, cursor, 0,
> +			      space_by_id(BOX_CK_CONSTRAINT_ID));
> +	sqlVdbeChangeP5(v, OPFLAG_SYSTEMSP);
> +	sqlVdbeAddOp4Int(v, OP_NoConflict, cursor, v->nOp + 3,
> +			 ck_constraint_reg, 2);
> +	sqlVdbeAddOp4(v, OP_Error, ER_CONSTRAINT_EXISTS, v->nOp + 1, 0, err,
> +		      P4_STATIC);
> +	sqlVdbeAddOp1(v, OP_Halt, -1);
> +	sqlVdbeAddOp1(v, OP_Close, cursor);

I don’t like code duplication: this snippet looks almost the same as
vdbe_emit_halt_with_presence_test(). Wouldn’t it be better if OP_Error
was integrated to that function? Also, why not move error setting
to OP_Error from other OP_Halt usages?

> +
> 	sqlVdbeAddOp3(v, OP_SInsert, BOX_CK_CONSTRAINT_ID, 0,
> 		      ck_constraint_reg + 5);
> 	save_record(parser, BOX_CK_CONSTRAINT_ID, ck_constraint_reg, 2,
> @@ -1131,14 +1138,19 @@ vdbe_emit_fk_constraint_create(struct Parse *parse_context,
> 	 * Lets check that constraint with this name hasn't
> 	 * been created before.
> 	 */
> -	const char *error_msg =
> +	const char *err =
> 		tt_sprintf(tnt_errcode_desc(ER_CONSTRAINT_EXISTS), name_copy);
> -	if (vdbe_emit_halt_with_presence_test(parse_context,
> -					      BOX_FK_CONSTRAINT_ID, 0,
> -					      constr_tuple_reg, 2,
> -					      ER_CONSTRAINT_EXISTS, error_msg,
> -					      false, OP_NoConflict) != 0)
> -		return;
> +	int cursor = parse_context->nTab++;
> +	vdbe_emit_open_cursor(parse_context, cursor, 0,
> +			      space_by_id(BOX_FK_CONSTRAINT_ID));
> +	sqlVdbeChangeP5(vdbe, OPFLAG_SYSTEMSP);
> +	sqlVdbeAddOp4Int(vdbe, OP_NoConflict, cursor, vdbe->nOp + 3,
> +			 constr_tuple_reg, 2);
> +	sqlVdbeAddOp4(vdbe, OP_Error, ER_CONSTRAINT_EXISTS, vdbe->nOp + 1, 0,
> +		      err, P4_STATIC);
> +	sqlVdbeAddOp1(vdbe, OP_Halt, -1);
> +	sqlVdbeAddOp1(vdbe, OP_Close, cursor);
> +
> 	sqlVdbeAddOp2(vdbe, OP_Bool, fk->is_deferred, constr_tuple_reg + 3);
> 	sqlVdbeAddOp4(vdbe, OP_String8, 0, constr_tuple_reg + 4, 0,
> 			  fk_constraint_match_strs[fk->match], P4_STATIC);
> diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
> index c8887f9..abf881a 100644
> --- a/src/box/sql/vdbe.c
> +++ b/src/box/sql/vdbe.c
> @@ -885,6 +885,18 @@ case OP_Goto: {             /* jump */
> 	goto jump_to_p2;
> }
> 
> +/* Opcode:  Error P1 P2 * P4 *

I’d call it OP_DiagError or OP_SetDiag.

> + *
> + * Setting an error and an unconditional jump to address P2.

Nit: -> Set an error and process unconditional jump …
Or -> Set an error and unconditionally jump to 

> + *
> + * The P1 parameter is error code of the erroe. The P4 parameter

-> is an error code to be set.

> + * is a description of the error.

-> is a text description.

> + */
> +case OP_Error: {             /* jump */
> +	box_error_set(__FILE__, __LINE__, pOp->p1, pOp->p4.z);

Why not simple diag_set() ?

> +	goto jump_to_p2;
> +}
> +

  reply	other threads:[~2019-06-26 16:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-25 15:31 [tarantool-patches] [PATCH v1 0/2] sql: clean-up in case constraint creation failed imeevma
2019-06-25 15:31 ` [tarantool-patches] [PATCH v1 1/2] sql: add OP_Error opcode in VDBE imeevma
2019-06-26 16:11   ` n.pettik [this message]
2019-06-25 15:31 ` [tarantool-patches] [PATCH v1 2/2] sql: clean-up in case constraint creation failed imeevma
2019-06-26 16:11   ` [tarantool-patches] " n.pettik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2CCDE513-7D85-41C7-A50D-3EDFA076EA8C@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v1 1/2] sql: add OP_Error opcode in VDBE' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox