folks. I got a query on SQLalchemy that is taking too long. I don't if it's because the db is too big (6.5 millions of rows, so I don't think so)or if I'm doing something wrong. The following are the tables.
class A(Base):
__tablename__ = 'tbl_a'
id = Column(Integer, primary_key=True, autoincrement=True)
a = Column(CHAR(3))
b = Column(DATE)
c = Column(Integer)
d = Column(Integer)
e = Column(Integer)
class B(Base):
__tablename__ = 'tbl_b'
id = Column(Integer, primary_key=True, autoincrement=True)
a = Column(Integer)
b = Column(DATE)
c = Column(Integer)
d = Column(Integer)
And this is the query:
row = session.query(A).get(id)
value = session.query(B.d).filter((B.b == row.b)&
(B.d == row.c)&
(B.e == row.d)).first()
With just one condition B.b == row.b
it takes 2 minutes, with more I didn't saw it end after 10 minutes. It takes 0.5 seconds to get the row
value. One thing that I saw was that indexing columns you intend to use the where clause one speed up things. If so, can I do it after I uploaded the records to my db?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…