# Analysing Performance of DB Queries

How can you understand if your Database queries are actually being indexed or not and how efficiently they are searching?

### PostgreSQL

Let's look at how we can analyze the queries in PostgreSQL:

```
explain analyze select id, name from employees where id = 12
```

### MongoDB

In case of mongodb as well there is an explain after collection name which you can use to understand the query performance:

You can use the `cursor.explain()` method or the `db.collection.explain()` method to determine whether or not a query uses an index. On using explain in mongodb queries you can notice that in case of query which requires full search will be in `COLLSCAN status.`

![](/files/3iHHupv3rUmLv3V42oeZ)

Now in case of efficient searching with indexes, it will be in the stage: IXSCAN

**References**

{% embed url="<https://database.guide/find-out-if-a-query-uses-an-index-in-mongodb>" %}

{% embed url="<https://youtu.be/-qNSXK7s7_w>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.kurianbenoy.com/databases/analysing-performance-of-db-queries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
