How to optimize search restricted by boolean column?
The expression is_principal is the same as is_principal &lt;&gt; 0, so the database assumes that all values except 0 are searched for, and estimates that most rows will match.

If the values in the is_principal column are proper booleans, you can get the database to assume a higher selectivity by searching for the value you actually want to search for:

SELECT yid, xid FROM x WHERE is_principal = 1


This query is likely to read the rows from the table in index order (i.e., random order), so if there is a large number of matching rows, performance will be worse.