JOIN
query on below table which contains large amount of data. This executes very slow with java jdbc and jpa.
Use case UI has an option to select list of traders,category and date range.If i select 1 week date range and all traders from dropdown, will the below query joins records from 1 week of stock table with all the records from stock_trader?
STOCK
------------------------------------------
stock_id long | PRIMARY KEY AUTO_INCREMENT
stock_code | varchar(10)
stock_name |varchar(10)
created_date |DATETIME
category |varchar(10)
STOCK_TRADER
-----------------------------------------
stock_id | long
trader_name | FULLTEXT
SQL query
Select * from STOCK st join stock_trader trad
on st.stock_id=trad.stock_id where st.created_date<CURRENT_TIMESTAMP()
and trad.trader_name in(:traderlist)
group by st.stock_id
traderlist: list of traders selected from UI
Please comment on the performance gain if I use the data model below which adds an extra column in stock_trader
and joining with multiple columns. Can i expect faster response of the below query which maps only 1 week of records from stock table with 1 week of traders from stock_trader.
- Is there any way to minimize the processing time of query?And what would be the average execution time for 1 million data.
what if the below join is replaced with a view and applying where clauses on the view from java jdbc/jpa. I found view makes the execution faster but am worried that it will join the whole dataset as where clauses are appllied dynamically from UI. If so performance would be much slower right?
STOCK_TRADER ----------------------------------------- stock_id | long trader_name | FULLTEXT created_date | DATETIME
SQL QUERY
Select * from STOCK st join stock_trader trad on st.stock_id=trad.stock_id and st.created_date =trad.created_date where st.created_date<CURRENT_TIMESTAMP() and trad.trader_name in(:traderlist) group by st.stock_id