Question

While updating all entries in my DB, between two of them I got the following query:

Product Load (1.1ms)  SELECT "products".* FROM "products" WHERE "products"."vtex_identifier" = '158677' LIMIT 1
 (0.2ms)  BEGIN
 (0.4ms)  UPDATE "products" SET "provider_id" = 3, "updated_at" = '2014-02-19 15:14:32.404889' WHERE "products"."id" = 469
 (0.5ms)  COMMIT
Product Load (5.8ms)  SELECT "products".* FROM "products" WHERE "products"."vtex_identifier" = '157683' LIMIT 1


EXPLAIN (0.5ms)  EXPLAIN SELECT "products".* FROM "products" WHERE "products"."vtex_identifier" = '157683' LIMIT 1
EXPLAIN for: SELECT  "products".* FROM "products"  WHERE "products"."vtex_identifier" = '157683' LIMIT 1
                           QUERY PLAN
------------------------------------------------------------------
Limit  (cost=0.00..226.53 rows=1 width=267)
->  Seq Scan on products  (cost=0.00..226.53 rows=1 width=267)
     Filter: ((vtex_identifier)::text = '157683'::text)
(3 rows)


 (0.2ms)  BEGIN
 (0.4ms)  UPDATE "products" SET "provider_id" = 3, "updated_at" = '2014-02-19 15:14:32.920676' WHERE "products"."id" = 470
 (0.5ms)  COMMIT

Does anybody know when and why it is called? Curiously, the text of other queries after this EXPLAIN command came all in bold style

Was it helpful?

Solution

ActiveRecord automatically runs EXPLAIN query to detect slow running queries. development environments get the following configuration. For any query that takes more than 0.5 seconds, it automatically runs EXPLAIN query.

config.active_record.auto_explain_threshold_in_seconds = 0.5

You can disable it by setting it to nil

config.active_record.auto_explain_threshold_in_seconds = nil

Read

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top