Skip to content

Instantly share code, notes, and snippets.

@kovid-rathee
Created February 14, 2019 16:21
Show Gist options
  • Save kovid-rathee/0abf27ca6dfa07d3e102c7d69653a95a to your computer and use it in GitHub Desktop.
Save kovid-rathee/0abf27ca6dfa07d3e102c7d69653a95a to your computer and use it in GitHub Desktop.
Create and Insert Scripts for Testing Insert Performance in MySQL WITH and WITHOUT primary keys
-- Create and Insert query for testing Insert performance for table WITH primary keys
create table test_inserts_with_primary_key (
id bigint not null auto_increment,
text_field_1 varchar(50),
text_field_2 varchar(50),
created_at date,
primary key (id)
) engine = innodb;
insert into test_inserts_with_primary_key
select null id,
md5(rand()) text_field_1,
md5(rand()) text_field_2,
curdate() - interval round(rand() * 200) day created_at;
-- Create and Insert query for testing Insert performance for table WITHOUT primary keys
create table test_inserts_without_primary_key (
id bigint not null,
text_field_1 varchar(50),
text_field_2 varchar(50),
created_at date
) engine = innodb;
insert into test_inserts_without_primary_key
select round(rand() * 100000) id,
md5(rand()) text_field_1,
md5(rand()) text_field_2,
curdate() - interval round(rand() * 200) day created_at;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment