Having a floating point number as part of the primary key (PK) is a killer. In this regard, it should not be part of any restrictions - Unique Key (Great Britain), Foreign Key (FK), etc.
To improve the performance of your SQL query many times, try changing the schema as shown below:
CREATE TABLE test ( item_id INTEGER, feature_id INTEGER, count INTEGER ); CREATE TABLE features ( id INTEGER, feature_value double not null ); CREATE TABLE items ( id INTEGER, item_description varchar2(100) not null ); ALTER TABLE test ADD CONSTRAINT fk_test_item_id foreign key (item_id) references items(id); ALTER TABLE test ADD CONSTRAINT fk_test_feature_id foreign key(feature_id) references features(id);
When your test table is normalized, as described above, I separate the elements and bind them to separate individual tables, and this becomes more than just a display table with a count of each display.
If you are currently running the SQL query that you fired earlier, with a few changes, as indicated below, you should see a significant / drastic improvement in the performance of SQL queries.
select t1.id, t2.id, sum( least( t1.count, t2.count )) as priority from test as t1 inner join test as t2 on t2.feature_id = t1.feature_id where t1.id = {some user supplied id value} group by t1.id, t2.id order by priority desc limit 500;
Hooray!
karthiks
source share