I have two questions:
- As my title, which one is more efficient for running large query on large volume of data?
I've looked at MySQL doc which explains about workbench's performance in https://www.mysql.com/products/workbench/performance/ however I cannot seem to find any resource that specifically talks about efficiency difference between running query on cmd and query on workbench.
How to optimize this query
select r.user_id, k.id as kickscooter_id, st_astext(k.location) as location, k.created_at, k.serial_number, k_st.serial_number as states_serial_number, st_astext(k_st.gps) as gps_location, k_st.gps_updated_at, r.start_time, r.end_time from kickscooters k join rents r on k.id= r.kickscooter_id join kickscooter_states_190614 k_st on k.serial_number = k_st.serial_number order by r.rent_date limit 999;
I've learned that creating an index allows mysql to sort things quickly therefore I've added index by
ALTER TABLE `tablename` ADD INDEX `indexname` (`columnname`);
following answers from one of SO post "order by" taking too much time in mysql
As suggested in comments I've executed
analyze <my query>
since my server is MariaDB.
which gave me ERROR CODE 2013: LOST connection to server during query.
When I ran
explain <my query>
It worked and outputs:
id select_type table type possible_keys
1 SIMPLE k_st ALL kickscooter_states_190614_serial_number_date_index
1 SIMPLE k ref PRIMARY,kickscooters_serial_number_unique,kickscooters_serial_number_index
1 SIMPLE r ref rents_kickscooter_id_foreign
-table continued
/ key key_len ref rows extra
null null null 192818947 Using temporary; Using filesort
kickscooters_serial_number_unique 27 kickgoing_db.k_st.serial_number 1
rents_kickscooter_id_foreign 4 kickgoing_db.k.id 143