While optimizing my query in Postgres, I noted that creating an index is always very fast, less than 1 second on a table with millions of rows.
But if there's no index, a query would take a few minutes or even more!
In my mind, when creating an index, Postgres has to scan all data of the columns those need to be indexed on at least once. So this operation should be similar to a query with a filter on the same columns that needs a sequence scan on a table.
Why is creating an index dramatically faster than a sequence scanning query?