if a rowid table has a primary key that consists of a single column and the declared type of that column is "INTEGER" in any mixture of upper and lower case, then the column becomes an alias for the rowid. Such a column is usually referred to as an "integer primary key". A PRIMARY KEY column only becomes an integer primary key if the declared type name is exactly "INTEGER". Other integer type names like "INT" or "BIGINT" or "SHORT INTEGER" or "UNSIGNED INTEGER" causes the primary key column to behave as an ordinary table column with integer affinity and a unique index, not as an alias for the rowid.
Zhainar, очевидно, это не та простая задача, которую вы так решаете. Кстати, учитывая объемы данных, вы решаете ее неверно. Отбирать N оптимальных элементов можно еще в процессе обсчета, не храня все миллионы результатов и ничего не сортируя.