为什么TypeORM使用FindOn(id)

时间:2019-06-05 08:38:44

标签: node.js postgresql typeorm

假设我有实体User。调用getRepository(User).findOne($ id)会生成两个查询:

SELECT DISTINCT "distinctAlias"."User_id" as "ids_User_id" FROM (SELECT "User"."id" AS "User_id" FROM "user" "User" LEFT JOIN ... WHERE "User"."id" IN ($1)) "distinctAlias" ORDER BY "User_id" ASC LIMIT 1 -- PARAMETERS: [4]
SELECT "User"."id" AS "User_id" FROM "user" "User" LEFT JOIN ... WHERE ("User"."id" IN ($1)) AND "User"."id" IN (4) -- PARAMETERS: [4]

为什么不选择一个查询ID = $ 1的查询,如果有多行返回拒绝承诺?

第一个是从select中选择,第二个是条件为double匹配的条件。这会影响PG的性能吗?

0 个答案:

没有答案