flask_sqlalchemy对千万级数据进行分页搜索如何提升性能,还是有10来秒的查询时间
if query == "":
waterinfo = db.session.query(Waterinfo).paginate(page=pagenum, per_page=pagesize)
else:
waterinfo = db.session.query(Waterinfo).filter(Waterinfo.rvnm.contains(query) | Waterinfo.stnm.contains(query)).paginate(page=pagenum,per_page=pagesize)
data_list = []
total = waterinfo.total
for i in waterinfo.items:
dic = {}
dic["id"] = i.id
dic["date"] = i.date
dic["rvnm"] = i.rvnm
dic["stnm"] = i.stnm
dic["wl"] = i.wl
dic["wp"] = i.wp
dic["ud"] = i.ud
dic["ql"] = i.ql
dic["fwl"] = i.fwl
dic["awl"] = i.awl
dic["gwl"] = i.gwl
data_list.append(dic)
return jsonify([data_list, total])