Efficiency of Select query [closed] - mysql

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Consider two queries,
Select * from table where size = 'L';
Select * from table where id IN (691,12,123,5123,....); # id is primary key for the table. and covers all the cases for which size ='L'.
Now consider a table which has 2 million records and i'll be firing both the queries.
Which of the two queries will run faster and why?
Consider this situation in terms of a system which filters out data on select of the option.

In Short: Ths answer depends on how many rows have size='L'. If there are many rows the the second will be more efficient because an index on size ist slow (cardinality).

Related

Is there any performance-wise difference between two ways of sql insert statement? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
1.insert into demotable1(list_of_all_columns) select * from demotable2 where some_condition;
2.insert into demotable1 select * from demotable2 where some_condition;
note: Table structure of demotable1 and demotable2 are same.
Which one of the above query statement is optimal?
"Optimal" -- They are the same.
MySQL will expand * into a list of columns as part of the parsing of the query. If you have a list of columns, it will verify that they are valid. So, no significant difference in performance. In general, performance of a query is dominated by fetching rows, not the details of what goes on inside the row.
"Desirable" --
On the other hand, * should not be used in most situations. What if you later added or deleted a column? Suddenly most queries with * in them would break. The main exception: You are simply dumping the data to see what is in the table.
Hence, option 3 is the only desirable version; it is unfortunate that it is not available.

How can I improve the query with grouping? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
How can I add a grouping for the "retirements" table by the "id_type" field and not just for everyone?
select name,
sum(retirements.price_per_product)
from retirements
join type_of_products top on retirements.id_product = top.id
where (date between '1998-11-01' and '1998-11-14')
group by name;
Do not resort to aggregate functions of each type? It's so rude.
There are two different ways to achieve this.
1. You may use a sub-query but it is expensive in terms of performance.
2. You may utilize the #temp table and join it in later part. A downside is it is
longer to code but performance is good especially in the long run.

Howto efficiently search a huge mysql table [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
if I had a mysql table that has, lets say 300 million rows, how would I search for a row using
SELECT id WHERE coloumn = "abc" ;
most efficiently? Can I prepare the data so it would help the sql searching through the data? Or does it parse the rows row by row?
The SQL 101 answer here is an index using CREATE INDEX:
CREATE INDEX column_index ON table_name (`column_name`)
This of course depends on your schema. You can index more than one column as well and can apply UNIQUE constraints to ensure that each value is used only once.
On large tables the CREATE INDEX operation will be brutally slow to create the first time, so schedule some downtime if necessary. Once created it will be kept up-to-date automatically.

How many records can be possible in mysql? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How many records can be possible & how many maximum records can be effective in mysql?
Actually my table has
24 Tables
1000000 Rows in Table (Each table (max))
Can I use mysql, please help me to solve my problem.
Yes you can use mysql perfectly.
One million rows (AKA records) is not too much for mysql, if you index that.

MYSQL avergae and MAX number [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I need to query a database table. structure:
id---bid ---veh_id---user_id
There is many data, all are veh_id related. User can place bid on veh_id as many as they want and on many veih_id.
I need to find the average bid on each veh_id and also the max bid receive for that veh_id. Can this be done in one SQL query. The optimal would have the difference betwenn the average and the max number. All group by veh_id.
I don't know where to start.
If I understood correctly:
SELECT MAX(bid), AVG(bid) FROM someTable GROUP BY veh_id