简体   繁体   中英

MYSQL generating queries I didn't ask for in my Rails application

I've been trying to fix my app's performance and after using Datadog to try to trace the problem I found out that my application is generating a bunch of SQL queries that I have no idea where they are coming from.

The top 3 queries being generated in the image below are queries that are not related to PreparationsController#index.

在此处输入图像描述

When looking at my application log after calling for PreparationsController#index, the only query referring to the ingredients_receipts and ingredients_preparation models are the following (these ones I actually called for them, but as you can see, they are a simple "exists" query): 在此处输入图像描述

Preparation.rb

在此处输入图像描述

PreparationsController#index

在此处输入图像描述

I've tried tracing it further down with DataDog but it won't go deeper than what the images are showing. I've been pulling my hairs out, any help is appreciated.

This just looks like two different log capturing methods producing slightly different results, notice that the third query in the Datadog screenshot has select ingredients.* so the first two that have select ? are not "normal" queries, so probably that placeholder is filled in with 1 as one just like your Rails log shows.

Seeing as they both seem to be id specific, that seems likely to be an n+1 problem, and probably simple to resolve with an includes .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM