Tarantool development patches archive
 help / color / mirror / Atom feed
From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Alex Khatskevich <avkhatskevich@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v2] sql: fix decode analyze sample
Date: Tue, 19 Jun 2018 04:12:06 +0300	[thread overview]
Message-ID: <B58CD8AC-D411-48A7-BCA2-61BB5A18B54D@tarantool.org> (raw)
In-Reply-To: <20180601165014.30131-1-avkhatskevich@tarantool.org>

Except for comments below, pls rebase on fresh 2.0.
Your branch seems to be way behind current master.

> int sqlite3Stat4ValueFromExpr(Parse *, Expr *, u8, sqlite3_value **);
> void sqlite3Stat4ProbeFree(UnpackedRecord *);
> -int sqlite3Stat4Column(sqlite3 *, const void *, int, int, sqlite3_value **);
> +
> +/*

Start comment with /**

> + * Extract the iCol-th column from the record in pRec.  Write
> + * the column value into *ppVal.  If *ppVal is initially NULL

Lets move from Hungarian notation to Tarantool-style naming.
Moreover, you didn’t specify args names in func prototype.

> + * then a new sqlite3_value object is allocated.
> + *
> + * If *ppVal is initially NULL then the caller is responsible for
> + * ensuring that the value written into *ppVal is eventually
> + * freed.
> + *
> + * @param db Database handle.
> + * @param pRec Pointer to buffer containing record.
> + * @param iCol Column to extract.
> + * @param[out] ppVal Extracted value.
> + *
> + * @retval Error code or SQLITE_OK.

Or SQLITE_OK on success (or 0 after fixes).

> + */
> +int
> +sql_stat4_column(struct sqlite3 *, const void *, int, sqlite3_value **);
> char sqlite3IndexColumnAffinity(sqlite3 *, Index *, int);
> 
> /*
> diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
> index f91d7119c..821d4db74 100644
> --- a/src/box/sql/vdbemem.c
> +++ b/src/box/sql/vdbemem.c
> @@ -1588,55 +1588,29 @@ sqlite3Stat4ValueFromExpr(Parse * pParse,	/* Parse context */
> 	return stat4ValueFromExpr(pParse, pExpr, affinity, 0, ppVal);
> }
> 
> -/*
> - * Extract the iCol-th column from the nRec-byte record in pRec.  Write
> - * the column value into *ppVal.  If *ppVal is initially NULL then a new
> - * sqlite3_value object is allocated.
> - *
> - * If *ppVal is initially NULL then the caller is responsible for
> - * ensuring that the value written into *ppVal is eventually freed.
> - */
> int
> -sqlite3Stat4Column(sqlite3 * db,	/* Database handle */
> -		   const void *pRec,	/* Pointer to buffer containing record */
> -		   int nRec,	/* Size of buffer pRec in bytes */
> -		   int iCol,	/* Column to extract */
> -		   sqlite3_value ** ppVal	/* OUT: Extracted value */
> -    )
> +sql_stat4_column(struct sqlite3 *db, const void *record, int col_num,
> +		 sqlite3_value **res)
> {
> -	u32 t;			/* a column type code */
> -	int nHdr;		/* Size of the header in the record */
> -	int iHdr;		/* Next unread header byte */
> -	int iField;		/* Next unread data byte */
> -	int szField = 0;	/* Size of the current data field */
> -	int i;			/* Column index */
> -	u8 *a = (u8 *) pRec;	/* Typecast byte array */
> -	Mem *pMem = *ppVal;	/* Write result into this Mem object */
> -
> -	assert(iCol > 0);
> -	iHdr = getVarint32(a, nHdr);
> -	if (nHdr > nRec || iHdr >= nHdr)
> -		return SQLITE_CORRUPT_BKPT;
> -	iField = nHdr;
> -	for (i = 0; i <= iCol; i++) {
> -		iHdr += getVarint32(&a[iHdr], t);
> -		testcase(iHdr == nHdr);
> -		testcase(iHdr == nHdr + 1);
> -		if (iHdr > nHdr)
> -			return SQLITE_CORRUPT_BKPT;
> -		szField = sqlite3VdbeSerialTypeLen(t);
> -		iField += szField;
> -	}
> -	testcase(iField == nRec);
> -	testcase(iField == nRec + 1);
> -	if (iField > nRec)
> -		return SQLITE_CORRUPT_BKPT;
> -	if (pMem == 0) {
> -		pMem = *ppVal = sqlite3ValueNew(db);
> -		if (pMem == 0)
> -			return SQLITE_NOMEM_BKPT;
> +	assert(col_num >= 0);
> +	/* Write result into this Mem object */

Put dots at the end of sentences.

> +	Mem *mem = *res;

Lets use struct prefix.

> +	/* Typecast byte array */
> +	const char *a = (const char *) record;

Lets pass already const char*. AFAIK all routine connected with MsgPack
accepts const char *, but not void *.

> +	assert(mp_typeof(a[0]) == MP_ARRAY);
> +	int col_cnt = mp_decode_array(&a);
> +	assert(col_cnt > col_num);
> +	for (int i = 0; i < col_num; i++)
> +		mp_next(&a);
> +	if (mem == 0) {

== NULL

> +		mem = *res = sqlite3ValueNew(db);

Don’t use double assignments.

> +		if (mem == 0) {

== NULL

> +			diag_set(OutOfMemory, sizeof(Mem), "sqlite3ValeuNew”,

sqlite3ValueNew

> +				 "mem");
> +			return -1;
> +		}
> 	}
> -	sqlite3VdbeSerialGet(&a[iField - szField], t, pMem);
> +	sqlite3VdbeMsgpackGet((const unsigned char *) record, mem);
> 	return SQLITE_OK;

Just return 0 (in fact, they are the same thing).

  reply	other threads:[~2018-06-19  1:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-01 16:50 [tarantool-patches] " AKhatskevich
2018-06-19  1:12 ` n.pettik [this message]
2018-06-19  8:18   ` [tarantool-patches] " Alex Khatskevich
2018-06-19 13:55     ` n.pettik
2018-06-19 14:59       ` Alex Khatskevich
2018-06-29 15:05         ` n.pettik
2018-06-29 15:09           ` Kirill Yukhin

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=B58CD8AC-D411-48A7-BCA2-61BB5A18B54D@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=avkhatskevich@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v2] sql: fix decode analyze sample' \
    /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