Skip to content

Instantly share code, notes, and snippets.

@chlp
Created May 7, 2019 16:28
Show Gist options
  • Save chlp/a61d4345b8f71f7acac03db5bc89af9e to your computer and use it in GitHub Desktop.
Save chlp/a61d4345b8f71f7acac03db5bc89af9e to your computer and use it in GitHub Desktop.
MySQL testing large tables
-- CREATE TABLE IF NOT EXISTS balances
-- (
-- address VARCHAR(40) NOT NULL,
-- timestamp BIGINT UNSIGNED NOT NULL,
-- balance BIGINT UNSIGNED NOT NULL,
-- PRIMARY KEY(address, timestamp)
-- );
--
-- SELECT balance FROM balances WHERE address=%s AND timestamp<%s ORDER BY timestamp DESC LIMIT 1;
DROP PROCEDURE IF EXISTS loop_insert;
CREATE PROCEDURE loop_insert()
BEGIN
DECLARE int_val INT DEFAULT 0;
test_loop : LOOP
IF (int_val = 1000000) THEN
LEAVE test_loop;
END IF;
INSERT INTO `balances`(`address`, `timestamp`, `balance`) VALUES
((int_val % 20), ROUND(int_val / 3), ROUND(RAND() * 100000));
SET int_val = int_val +1;
END LOOP;
END;
call loop_insert;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment