Bug #100474 mysqlslap won't create a table if --auto-generate-sql-write-number=0
Submitted: 10 Aug 2020 6:50 Modified: 10 Aug 2020 7:25
Reporter: Ryusuke Kajiyama Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:8.0.21,5.6.48, 5.7.31 OS:Any
Assigned to: CPU Architecture:Any
Tags: mysqlslap

[10 Aug 2020 6:50] Ryusuke Kajiyama
Description:
If --auto-generate-sql-write-number=0 is used, mysqlslap won't create any table for benchmark, which results error if running against a server.
To test against empty table, --auto-generate-sql-write-number=0 should work, creating table without data.

How to repeat:
$ mysqlslap -a --auto-generate-sql-write-number=0 --only-print
DROP SCHEMA IF EXISTS `mysqlslap`;
CREATE SCHEMA `mysqlslap`;
use mysqlslap;
INSERT INTO t1 VALUES <snip>
DROP SCHEMA IF EXISTS `mysqlslap`;

Suggested fix:
Creating table without data, when --auto-generate-sql-write-number=0 is set.
[10 Aug 2020 7:10] Ryusuke Kajiyama
If --auto-generate-sql-write-number=1, mysqlslap only creates a table.
If --auto-generate-sql-write-number=2, only single row inserted.

====
$ mysqlslap -a --auto-generate-sql-write-number=2 --auto-generate-sql-load-type=read --number-of-queries=1 --only-print

DROP SCHEMA IF EXISTS `mysqlslap`;
CREATE SCHEMA `mysqlslap`;
use mysqlslap;
CREATE TABLE `t1` (intcol1 INT(32) ,charcol1 VARCHAR(128));
INSERT INTO t1 VALUES (1804289383,'mxvtvmC9127qJNm06sGB8R92q2j7vTiiITRDGXM9ZLzkdekbWtmXKwZ2qG1llkRw5m9DHOFilEREk3q7oce8O3BEJC0woJsm6uzFAEynLH2xCsw1KQ1lT4zg9rdxBL');
SELECT intcol1,charcol1 FROM t1;
DROP SCHEMA IF EXISTS `mysqlslap`;
====

Can following fix the issue?
https://github.com/mysql/mysql-server/blob/8.0/client/mysqlslap.cc#L1579
-  if (auto_generate_sql && (auto_generate_sql_number > count)) {
+  if (auto_generate_sql && (auto_generate_sql_number >= count)) {
[10 Aug 2020 7:25] MySQL Verification Team
Hello Kajiyama-San,

Thank you for the report and feedback.

regards,
Umesh