sqlite where 語句的 like 和 = 相差多少

來源:互聯網
上載者:User
 1 #!/usr/bin/env python 2  3 ''' 4 genearte the sqlite db 5 ''' 6 import time 7 import apsw 8  9 10 LOOP_INSERT = 1000011 LOOP_SEARCH = 100012 13 def genDB():14     loop_time = LOOP_INSERT15     db = apsw.Connection(":memory:")16     cursor = db.cursor()17     cursor.execute("create table big(itemall string);")18     cursor.execute("begin;")19     for i in xrange(loop_time):20         cursor.execute("insert into big (itemall) values (%010d); " % i)21 22     cursor.execute("commit;")23 24     cursor.execute("create table small(idx int primary key, v1 int, v2 char);")25     cursor.execute("begin;")26     for i in xrange(loop_time):27         cursor.execute("insert into small (v1, v2) values (%d, %010d); " % (i, i))28 29     cursor.execute("commit;")30 31     return db32 33 34 def test1(db):35     c = db.cursor()36     start = time.time()37     for i in xrange(LOOP_SEARCH):38         c2 = c.execute("select * from big where itemall like '%010d' LIMIT 1;" % i)39         values = c2.fetchall()40         if len(values) > 0:41             pass42     end = time.time()43     44     print "duration test1 ", end - start45     46 47 def test2(db):48     c = db.cursor()49     start = time.time()50     for i in xrange(LOOP_SEARCH):51         c2 = c.execute("select * from small where v1 = '%010d' and v2 = %10d LIMIT 1;" % (i, i))52         values = c2.fetchall()53         if len(values) > 0:54             pass55     end = time.time()56     57     print "duration test2 ", end - start58         59 60 def main():61     db = genDB()62     test1(db)63     test2(db)64     65 66 if __name__ == '__main__':67     main()

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.