/test/decisions/sep_type_column.py

http://pickled-object-database.googlecode.com/ · Python · 89 lines · 72 code · 15 blank · 2 comment · 6 complexity · 2c72bd740018d0318f2ef99a1f7290bf MD5 · raw file

  1. import sqlite3
  2. import time
  3. import ajc
  4. db_one = sqlite3.connect('sep.one.sqlite3')
  5. cu_one = db_one.cursor()
  6. cu_one.execute("CREATE TABLE IF NOT EXISTS my_table (fid INTEGER, key TEXT, value TEXT, PRIMARY KEY (fid, key))")
  7. db_two = sqlite3.connect('sep.two.sqlite3')
  8. cu_two = db_two.cursor()
  9. cu_two.execute("CREATE TABLE IF NOT EXISTS my_table (fid INTEGER, key TEXT, type TEXT, value TEXT, PRIMARY KEY (fid, key))")
  10. N = 100000
  11. def i1():
  12. ajc.util.time_start(msg = '1 column insert')
  13. for i in range(N):
  14. cu_one.execute('INSERT OR REPLACE INTO my_table (fid, key, value) VALUES (?,?,?)', (i, 'a_key', 'i' + str(i),))
  15. cu_one.execute('INSERT OR REPLACE INTO my_table (fid, key, value) VALUES (?,?,?)', (i, 'b_key', 'i' + str(4),))
  16. db_one.commit()
  17. ajc.util.time_stop()
  18. def i2():
  19. ajc.util.time_start(msg = '2 column insert')
  20. for i in range(N):
  21. cu_two.execute('INSERT OR REPLACE INTO my_table (fid, key, type, value) VALUES (?,?,?,?)', (i, 'a_key', 'i', i,))
  22. cu_two.execute('INSERT OR REPLACE INTO my_table (fid, key, type, value) VALUES (?,?,?,?)', (i, 'b_key', 'i', 4,))
  23. db_two.commit()
  24. ajc.util.time_stop()
  25. def e1():
  26. ajc.util.time_start(msg = '1 column query equals')
  27. for row in cu_one.execute("SELECT fid FROM my_table WHERE key = 'b_key' AND value = 'i4'"):
  28. fid = row[0]
  29. db_one.commit()
  30. ajc.util.time_stop()
  31. def e2():
  32. ajc.util.time_start(msg = '2 column query equals')
  33. for row in cu_two.execute("SELECT fid FROM my_table WHERE key = 'b_key' AND type = 'i' AND value = '4'"):
  34. fid = row[0]
  35. db_two.commit()
  36. ajc.util.time_stop()
  37. def l1():
  38. ajc.util.time_start(msg = '1 column query less than')
  39. for row in cu_one.execute("SELECT fid FROM my_table WHERE key = 'b_key' AND substr(value,1,1) = 'i' AND 1*substr(value,2) < 75000"):
  40. fid = row[0]
  41. #print "A", fid
  42. db_one.commit()
  43. ajc.util.time_stop()
  44. def l2():
  45. ajc.util.time_start(msg = '2 column query less than')
  46. for row in cu_two.execute("SELECT fid FROM my_table WHERE key = 'b_key' AND type = 'i' AND 1*value < 75000"):
  47. fid = row[0]
  48. #print "B", fid
  49. db_two.commit()
  50. ajc.util.time_stop()
  51. i1()
  52. i2()
  53. i2()
  54. i2()
  55. i1()
  56. i1()
  57. i2()
  58. i1()
  59. e2()
  60. e1()
  61. e2()
  62. e2()
  63. e1()
  64. e1()
  65. e2()
  66. e1()
  67. l2()
  68. l1()
  69. l2()
  70. l2()
  71. l1()
  72. l1()
  73. l2()
  74. l1()