Hi friends im having an issue where my query hangs...
# orm-help
k
Hi friends im having an issue where my query hangs, any idea how i can debug this
Copy code
const brands = await PrismaService.brand.findMany({
            distinct: ["name"],
            select: {
                id: true,
                name: true,
                image: {
                    select: {
                        source: true,
                        dtype: true,
                    },
                },
            },
        });
Copy code
prisma:info Starting a mysql pool with 9 connections.
prisma:query SELECT `checkpoint_gg`.`brand`.`id`, `checkpoint_gg`.`brand`.`name`, `checkpoint_gg`.`brand`.`image_id` FROM `checkpoint_gg`.`brand` WHERE 1=1
Seems like it does not like joining on that image table any idea why?
n
Hey 👋 Does only this query hang and other queries work as expected?
k
Hey
Thats right
If i comment out that join on image
Copy code
image: {
                    select: {
                        source: true,
                        dtype: true,
                    },
It works
@Nurul im introspecting my db to pull the models, do you want to see the models for brand and image?
n
If you directly run the raw query
Copy code
SELECT `checkpoint_gg`.`brand`.`id`, `checkpoint_gg`.`brand`.`name`, `checkpoint_gg`.`brand`.`image_id` FROM `checkpoint_gg`.`brand` WHERE 1=1
then does it work as expected?
k
yes
but thats not the whole raw query right, its missing the joining of the image, and thats where its hanging
n
Yes this query doesn’t include source and dtype. Are you on latest `@prisma/client`version?
k
yes
n
Latest version is
3.13.0
k
it never logs the query for the join, its hanging
Copy code
"prisma": "^3.13.0",
        "@prisma/client": "^3.13.0",
👍 1
Now get this...
i added the following line
Copy code
where: { created_at: { lte: new Date("2022-01-01") } },
and the same query now works!
it seems like there is some data after this date that is causing thsi query to hang
or some schema mismatch?
n
That’s strange 🤔
k
prisma does not like something with joining on image
but if i do the raw query i intend in mysql it works
Copy code
SELECT DISTINCT(b.name), b.id, i.source, i.dtype, b.created_at, i.id, b.image_id
FROM brand b
JOIN image i on i.id = b.image_id
order by b.created_at desc
n
Can you try if the query hangs when you try this?
Copy code
const brands = await PrismaService.brand.findMany({
            distinct: ["name"],
            select: {
                id: true,
                name: true,
                image: true,
            },
        });
k
yes it still hangs, so its not specific to those 2 fields
n
This is something our team would like to have a deeper look at, Could you please create a Bug Report here and describe the behaviour so that we could fix it in next versions
As a workaround for now I would suggest you to directly invoke raw query
k
Could it be with some data that has been added to the table which causes the query to no longer work
without knowing what that data is, i think a bug report would not help here
@Nurul because ive mentioned when adding that where caluse it works
n
Do you find any discrepancy in data which is inserted after the date that you tried in where clause?
Maybe if you could find the date from which the query starts hanging then we could have a look at the data of that specific date
k
there is a lot of data that has been added, and the usual raw query in mysql works. Its very difficult to debug this hanging issue when prisma gives no indiciation of what is happening/trying to do
Do you understand what i mean, if raw sql query works in mysql, the data that has been inserted has been accepted and can succesfully be queried by mysql, but when prisma is making that same query it hangs
its obvious to me that prisma does not like the data (because of that where clause) but ive no idea what is has an issue with and from my eyes looking at the data in the table it looks normal
n
Yes I got it, raw sql works but the strange thing is that there is no query output while logging. Have you added all log levels?
Copy code
const prisma = new PrismaClient({
  log: ['query', 'info', 'warn', 'error'],
})
k
yes
ye that is a problem , ive no way of knowing what prisma is doing when its hanging like that
Ive opted to use a raw query instead for now
Copy code
const brands = await PrismaService.$queryRaw`
            SELECT DISTINCT(b.name), b.id, i.source, i.dtype
            FROM brand b
            JOIN image i on i.id = b.image_id
            `;
👍 1