Question: Hello Stack Overflow community, I wanted to get the row number of the first element that meets the condition specified in the query. I am making the queries using Postgresql and I send them from Python.
Here is an outline of what I want:

```
+--------+---------------+
|name    |country        |
|--------|---------------|
|Juan    | United States |
|--------|---------------|
|Carlos  | France        |
|--------|---------------|
|Lucy    | UK            |
+--------+---------------+

```

In this case I would like to make a query where I can get the row number of the first person whose country is France (that is, row 2). Thank you. Anything that is not clear you can ask me.

Answer: 
Just posting an answer to help anybody who stumbles upon this in the future. As @Shawn said in his comment above, running the ANALYZE command was key to fixing this problem for me. Even though there are covering indexes, SQLITE doesn't always use them without the ANALYZE run.
First, I would write the query as:

```
FROM Dates JOIN
     A
     ON A.Date_c1 = Dates.Date_cal1 JOIN
     B
     ON B.Date_c1 = A.Date_c1 AND
        B.Object_Id = A.Object_Id JOIN
     C
     ON C.Date_c2 = Dates.Date_cal2 AND C.Object_Id = A.Object_Id
WHERE A.Object_Id = 14

```

I would suggest indexes on:

* `A(ObjectId, Date_c1)`
* `B(Object_Id, Date_c1)`
* `Dates(Date_cal1, Date_cal2)`
* `C(Objet_Id Date_C2)`

This should allow the `where` clause to filter the data using an index, with the rest of the joins using indexes as well.