Code Monkey home page Code Monkey logo

Comments (1)

xkikeg avatar xkikeg commented on July 29, 2024

結論

  • 作ったビューに対してline.linename LIKE '東海道'とかしてしまうと実行時間がとても遅くなることが分かった。
    • ちなみにline NATURAL JOIN ...すると若干は早い(でもちょっと遅い)
  • 一方line.lineid=69のように直接路線IDで引くと早いことが分かった。

実行環境

あと、X201s(Ubuntu 11.10 oneiric)で実行するとCore i7の威力なのかSQLite3のバージョンが3.7.3から3.7.7に上がったからか、めっちゃ早い。

  • 一応実行計画読んでみたけど意味不明。
  • Pythonで実験したところX201sでは25%程度のオーバヘッドが加わる。
  • 一方T40 (Debian squeeze)ではidで引くと1秒/op.程度なのがname LIKEで11秒/op.になる。これはアーキテクチャというよりはSQLiteの実装がショボかったんではという気がしてくる。

結論としてはどうせlinenameでLIKEするうっかりさんはいるんだから最初からlineも結合しておけば便利なんじゃねという感じ。実験用のコードは下に示す。

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sqlite3
import time

DB = sqlite3.connect("ares.sqlite")

def lineid():
    for i in range(100):
        cur = DB.execute(u"SELECT * FROM station_kilo NATURAL JOIN line WHERE lineid=69")
        for i in cur: pass

def linename():
    for i in range(100):
        cur = DB.execute(u"SELECT * FROM station_kilo NATURAL JOIN line WHERE linename LIKE '東海道'")
        for i in cur: pass

def get_time(function):
    begin = time.clock()
    function()
    end = time.clock()
    return end - begin

print "lineid: ", get_time(lineid), "sec"
print "linename: ", get_time(linename), "sec"

from ares.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.