CRVV
2017-10-27 23:44:38 +08:00
大概试了一下,在我的机器上,含生成随机数据一共大约 400 秒,其中建索引 80 秒,查询 60 秒。
内存占用不超过 20 M,数据库文件 6.4 G
import sqlite3
import string
import random
conn = sqlite3.connect('test.db')
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS a (v TEXT)')
c.execute('CREATE TABLE IF NOT EXISTS b (v TEXT)')
letters = string.ascii_letters + string.digits
for _ in range(5_000_000):
____random_string = ''.join((random.choice(letters) for _ in range(random.randint(10, 100))))
____c.execute('INSERT INTO a VALUES (?)', (random_string, ))
for _ in range(50_000_000 // 4_500_000):
____c.execute('INSERT INTO b SELECT * FROM a LIMIT 4500000')
c.execute('CREATE INDEX bv ON b(v)')
c.execute('SELECT v FROM a WHERE v NOT IN (SELECT v FROM b)')
count = 0
for _ in c:
____count += 1
print(count)
conn.commit()
conn.close()