ids = tuple(m['id'] for m in relevant_models)
raw_q = db.executesql("""
SELECT
*
FROM "table"
WHERE ("table".ref_id" IN {});
""".format(str(ids)), as_dict=True)
#################### 1.8s
ids =
tuple(m['id'] for m in relevant_models)
dal_q = db(
db.table.ref_id.belongs(ids)
).select(db.table.ALL).as_list()
##################### 0.09s
Web2Py 2.22.3
Why would the dal query be so much slower than the raw sql? The generated sql (db._lastsql) is the same as the raw.