Skip to content

Instantly share code, notes, and snippets.

@Roguelazer
Created April 18, 2018 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Roguelazer/79e0eac7d3361cca25d00b12dee9932a to your computer and use it in GitHub Desktop.
Save Roguelazer/79e0eac7d3361cca25d00b12dee9932a to your computer and use it in GitHub Desktop.
import argparse
import MySQLdb
import time
def main():
parser = argparse.ArgumentParser()
args = parser.parse_args()
conn = MySQLdb.connect(db='ghtest')
cursor = conn.cursor()
cursor.execute('DROP TABLE IF EXISTS ghtest')
cursor.execute('DROP TABLE IF EXISTS _ghtest_gho')
cursor.execute('DROP TABLE IF EXISTS _ghtest_del')
cursor.execute('CREATE TABLE ghtest (id BIGINT AUTO_INCREMENT PRIMARY KEY, to_drop INT DEFAULT NULL, value MEDIUMTEXT DEFAULT NULL, other_field BOOLEAN DEFAULT FALSE, always_null INT DEFAULT NULL)')
for i in range(102400):
cursor.execute('INSERT INTO ghtest(value) VALUES(%s)', (str(i),))
print('created, will do insertions and updates for next 30s')
start = time.time()
while time.time() - start < 30:
conn.begin()
cursor.execute('INSERT INTO ghtest(value, other_field) VALUES (%s, %s)', (str(i), False))
pk = cursor.lastrowid
conn.commit()
conn.begin()
cursor.execute('UPDATE ghtest SET other_field=%s WHERE id=%s', (True, pk))
conn.commit()
print('done')
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment