Reputation:
Yes yes yes! I know! This is totally wrong to pass SQL in rails like the command below but I promise!:) it is just for some benchmark purposes
@medications = TestPharmOrderMain.select("brand_name,form,dose,generic_name as alternative,sum (order_count)
as total_count
,sum(order_cost) as total_cost").group("brand_name,form,dose,generic_name").limit(5)
The PostgresQL that I am running this REST service on it has two million rows and it takes like four minutes to return me the JSON from this query which is impossible to develop against it.
Is there a way I can change this query to for example only look at the first twenty rows in the DB and not two million rows so it runs faster for my dev purposes?
Upvotes: 0
Views: 42
Reputation: 24316
If this is for dev purposes do the smart thing and create a tiny database that is representative of the whole system. You can do this with a create table as select statement:
Create table my_test_table
as
select brand_name,form,dose,generic_name as alternative,sum (order_count)
as total_count
,sum(order_cost) as total_cost
from table
group by brand_name,form,dose,generic_name
limit 5
Now you can point your test query to my_test_table
and it will only have 5 records and will therefore be quite fast.
Now you can also offset this to something like DBUnit, which is essentially a framework that is laid on top of XUnit. So this can be easily integrated into your testing that is done in what I presume is RubyUnit.
Upvotes: 2