title: Sqlite executemany and DELETE
body: <p>Execute many seems to be very slow with deletion (Insertion is fine) and I was wondering if anyone knows why it takes so long.</p>
  <p>Consider the code below:</p>
  <pre><code>import sqlite3
  
  db = sqlite3.connect(&quot;mydb&quot;)
  c = db.cursor()
  c.execute(&quot;DROP TABLE IF EXISTS testing &quot;)
  c.execute(&quot;CREATE TABLE testing (val INTEGER);&quot;)
  my_vals2 = [[x] for x in range(1,10000)]
  
  def insertmany(vals):
      c.executemany(&quot;INSERT INTO testing (val) VALUES (?)&quot;,vals)
      db.commit()
  
  def deletemany1(vals):
      c.executemany(&quot;DELETE FROM testing WHERE val=?&quot;,vals)
      db.commit()
  
  def deletemany2(vals): #this is fastest even though im looping over to convert to strings and again to join ...
      vals = [&quot;'%s'&quot;%v[0] for v in vals] 
      c.execute(&quot;DELETE FROM testing WHERE val IN (%s)&quot;%&quot;,&quot;.join(vals))
      #DELETE FROM TABLE WHERE x in (1,2,3...)
  </code></pre>
  <p>And the following time results (timeit was giving funny data so :/) from IPython:</p>
  <pre><code>%time insertmany(my_vals2) 
  #CPU times: user 0.60 s, sys: 0.00 s, total: 0.60 s Wall time: 0.60 s
  
  %time deletemany1(my_vals2)
  #CPU times: user 3.58 s, sys: 0.00 s, total: 3.58 s Wall time: 3.58 s
  
  %time deletemany2(my_vals2)
  #CPU times: user 0.02 s, sys: 0.00 s, total: 0.02 s Wall time: 0.02 s
  </code></pre>
  <p>And just for the sake of completeness here are the timeit results (but I think timeit is broken on the second test(that or the ms is a different unit then the first test))</p>
  <pre><code>%timeit insertmany(my_vals2) 
  #1 loops, best of 3: 358 ms per loop
  
  %timeit deletemany1(my_vals2)
  #1 loops, best of 3: 8.34 ms per loop  &lt;- this is not faster than the above!!!! (timeit lies?)
  
  %timeit deletemany2(my_vals2)
  #100 loops, best of 3: 2.3 ms per loop  
  </code></pre>
  <p>So why is <code>executemany</code> soooooo slow with deletes?</p>