Yann Buydens
08/23/2022, 6:44 AMprisma.concept.findMany({
where: {
dictionaryId: Number(dictId),
name: {contains: foo}
},
include: {
_count: {
select: {
declarations: true, // including this in the query makes it super slow
},
},
}
})
I have a concept table and a declaration table. Concept and declaration have a many to many relationship. The declaration table has more than 500k rows, same goes for concept table.
longer explanation: https://www.loom.com/share/ff8d3034898e4ad08b8d19f044d500feJeremy Hinegardner
08/23/2022, 3:46 PMYann Buydens
08/24/2022, 6:08 AMmodel Concept {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @db.VarChar(255)
definition String?
declarations Declaration[] @relation(references: [id])
tags Tag[] @relation(references: [id])
dictionary Dictionary @relation(fields: [dictionaryId], references: [id], onDelete: Cascade)
dictionaryId Int
ignore Boolean? @default(false)
conceptValidation ConceptValidation?
DeltaAnalysisResult DeltaAnalysisResult? @relation(fields: [deltaAnalysisResultId], references: [id])
deltaAnalysisResultId String?
deltaAnalysisResultsWhereConsideredNew NewConceptsInDeltaAnalysisResult[]
@@unique([name, dictionaryId])
}
model Declaration {
id String @id @default(cuid())
name String @db.VarChar(255)
concepts Concept[] @relation(references: [id])
location Location @relation(fields: [locationId], references: [id])
locationId String
repo_url String
branch_name String
commit_hash String
tags Tag[] @relation(references: [id])
}
thx for helping me out 🙏 appreciate itJeremy Hinegardner
08/24/2022, 6:21 PMconcept and declaration so there is a join table under the covers, and I'd want to look and see if there are indexes on it.Jeremy Hinegardner
08/24/2022, 6:22 PMYann Buydens
08/25/2022, 5:55 AM-- DDL generated by Postico 1.5.20
-- Not all database features are supported. Do not use for backup.
-- Table Definition ----------------------------------------------
CREATE TABLE "_ConceptToDeclaration" (
"A" integer NOT NULL REFERENCES "Concept"(id) ON DELETE CASCADE ON UPDATE CASCADE,
"B" text NOT NULL REFERENCES "Declaration"(id) ON DELETE CASCADE ON UPDATE CASCADE
);
-- Indices -------------------------------------------------------
CREATE UNIQUE INDEX "_ConceptToDeclaration_AB_unique" ON "_ConceptToDeclaration"("A" int4_ops,"B" text_ops);
CREATE INDEX "_ConceptToDeclaration_B_index" ON "_ConceptToDeclaration"("B" text_ops);Yann Buydens
08/25/2022, 5:55 AM-- DDL generated by Postico 1.5.20
-- Not all database features are supported. Do not use for backup.
-- Table Definition ----------------------------------------------
CREATE TABLE "Concept" (
id integer DEFAULT nextval('"Concept_id_seq"'::regclass) PRIMARY KEY,
"createdAt" timestamp(3) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" timestamp(3) without time zone NOT NULL,
name character varying(255) NOT NULL,
definition text,
"dictionaryId" integer NOT NULL REFERENCES "Dictionary"(id) ON DELETE CASCADE ON UPDATE CASCADE,
ignore boolean DEFAULT false,
"deltaAnalysisResultId" text REFERENCES "DeltaAnalysisResult"(id) ON DELETE SET NULL ON UPDATE CASCADE
);
-- Indices -------------------------------------------------------
CREATE UNIQUE INDEX "Concept_pkey" ON "Concept"(id int4_ops);
CREATE UNIQUE INDEX "Concept_name_dictionaryId_key" ON "Concept"(name text_ops,"dictionaryId" int4_ops);Yann Buydens
08/25/2022, 5:56 AM-- DDL generated by Postico 1.5.20
-- Not all database features are supported. Do not use for backup.
-- Table Definition ----------------------------------------------
CREATE TABLE "Declaration" (
id text PRIMARY KEY,
name character varying(255) NOT NULL,
"locationId" text NOT NULL REFERENCES "Location"(id) ON DELETE RESTRICT ON UPDATE CASCADE,
repo_url text NOT NULL,
branch_name text NOT NULL,
commit_hash text NOT NULL
);
-- Indices -------------------------------------------------------
CREATE UNIQUE INDEX "Declaration_pkey" ON "Declaration"(id text_ops);Jeremy Hinegardner
08/25/2022, 9:08 PMYann Buydens
08/26/2022, 5:53 AM