Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Nikita Pettik <korablev@tarantool.org>, tarantool-patches@freelists.org
Subject: [tarantool-patches] Re: [PATCH v2 4/4] sql: rename changes() to row_count()
Date: Wed, 14 Nov 2018 15:32:56 +0300	[thread overview]
Message-ID: <acc21555-e76b-d3ca-4549-4eb655b68e82@tarantool.org> (raw)
In-Reply-To: <c8464301d49538d186b556e4468b6928f3737a2a.1542124689.git.korablev@tarantool.org>

Thanks for the patch!

> diff --git a/test/sql/row-count.result b/test/sql/row-count.result
> new file mode 100644
> index 000000000..7577d2795
> --- /dev/null
> +++ b/test/sql/row-count.result
> @@ -0,0 +1,157 @@
> +test_run = require('test_run').new()
> +---
> +...
> +engine = test_run:get_cfg('engine')
> +---
> +...
> +box.sql.execute('pragma sql_default_engine=\''..engine..'\'')
> +---
> +...
> +-- Test cases concerning row count calculations.
> +--
> +box.sql.execute("CREATE TABLE t1 (s1 CHAR(10) PRIMARY KEY);")
> +---
> +...
> +box.sql.execute("SELECT ROW_COUNT();")
> +---
> +- - [1]
> +...
> +box.sql.execute("SELECT ROW_COUNT();")
> +---
> +- - [0]

1. As I understand, ROW_COUNT() should return > 0 only in a
not empty transaction. Here you got rowcount > 0 after DDL
transaction is committed. Also, twice in a row called
row_count() returning different values looks weird.

'rowcount' should be returned as a metavalue from a DDL/DML
when box.sql.execute is removed.

> diff --git a/test/sql/row-count.test.lua b/test/sql/row-count.test.lua
> new file mode 100644
> index 000000000..38d3520c2
> --- /dev/null
> +++ b/test/sql/row-count.test.lua
> @@ -0,0 +1,54 @@
> +test_run = require('test_run').new()
> +engine = test_run:get_cfg('engine')
> +box.sql.execute('pragma sql_default_engine=\''..engine..'\'')
> +
> +-- Test cases concerning row count calculations.
> +--
> +box.sql.execute("CREATE TABLE t1 (s1 CHAR(10) PRIMARY KEY);")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("CREATE TABLE t2 (s1 CHAR(10) PRIMARY KEY, s2 CHAR(10) REFERENCES t1 ON DELETE CASCADE);")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("CREATE TABLE t3 (i1 INT PRIMARY KEY, i2 INT);")
> +box.sql.execute("INSERT INTO t3 VALUES (0, 0);")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("CREATE TRIGGER x AFTER DELETE ON t1 FOR EACH ROW BEGIN UPDATE t3 SET i1 = i1 + ROW_COUNT(); END;")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("INSERT INTO t1 VALUES ('a');")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("INSERT INTO t2 VALUES ('a','a');")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("INSERT INTO t1 VALUES ('b'), ('c'), ('d');")
> +box.sql.execute("SELECT ROW_COUNT();")
> +-- REPLACE is accounted for two operations: DELETE + INSERT.
> +box.sql.execute("REPLACE INTO t2 VALUES('a', 'c');")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("DELETE FROM t1;")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("INSERT INTO t3 VALUES (1, 1), (2, 2), (3, 3);")
> +box.sql.execute("TRUNCATE TABLE t3;")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("INSERT INTO t3 VALUES (1, 1), (2, 2), (3, 3);")
> +box.sql.execute("UPDATE t3 SET i2 = 666;")
> +box.sql.execute("SELECT ROW_COUNT();")
> +
> +-- All statements which are not accounted as DML should
> +-- return 0 (zero) as a row count.
> +--
> +box.sql.execute("START TRANSACTION;")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("COMMIT;")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("COMMIT;")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("ANALYZE;")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute("EXPLAIN QUERY PLAN INSERT INTO t1 VALUES ('b'), ('c'), ('d');")
> +box.sql.execute("SELECT ROW_COUNT();")
> +box.sql.execute('PRAGMA recursive_triggers')
> +
> +-- Clean-up.
> +--
> +box.sql.execute("DROP TABLE t2;")
> +box.sql.execute("DROP TABLE t3;")
> +box.sql.execute("DROP TABLE t1;")
> \ No newline at end of file

2. "No newline at end of file."

  reply	other threads:[~2018-11-14 12:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-13 16:11 [tarantool-patches] [PATCH v2 0/4] Introduce row_count() function Nikita Pettik
2018-11-13 16:11 ` [tarantool-patches] [PATCH v2 1/4] sql: don't increment row count on FK creation within CREATE TABLE Nikita Pettik
2018-11-14 12:32   ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-14 16:20     ` n.pettik
2018-11-13 16:11 ` [tarantool-patches] [PATCH v2 2/4] sql: account REPLACE as two row changes Nikita Pettik
2018-11-14 12:32   ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-14 16:20     ` n.pettik
2018-11-13 16:11 ` [tarantool-patches] [PATCH v2 3/4] sql: remove total_changes() function Nikita Pettik
2018-11-13 16:11 ` [tarantool-patches] [PATCH v2 4/4] sql: rename changes() to row_count() Nikita Pettik
2018-11-14 12:32   ` Vladislav Shpilevoy [this message]
2018-11-14 16:20     ` [tarantool-patches] " n.pettik
2018-11-14 16:43       ` Vladislav Shpilevoy
2018-11-15  5:06 ` [tarantool-patches] Re: [PATCH v2 0/4] Introduce row_count() function 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=acc21555-e76b-d3ca-4549-4eb655b68e82@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v2 4/4] sql: rename changes() to row_count()' \
    /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