Howto efficiently search a huge mysql table [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 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.

Related

Copy rows filtered on a search criteria from one table to another in MySQL [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 3 years ago.
Improve this question
Using MySQL, I want to retrieve all rows from a table A where a field contains "EQ" for example, copy them into table B (which has exactly the same field), and then delete them from table A.
I heard about triggers. Is that the right approach?
You need 2 SQL statements. First for inserting the data rows from A to B, and then for deleting those rows from A.
INSERT INTO B
SELECT *
FROM A
WHERE Field LIKE '%EQ%';
DELETE
FROM A
WHERE Field LIKE '%EQ%';
Triggers are a way to automate some activities when some other activity in a separate table happens. If you need to make sure that the above 2 operations should be triggered as soon someone INSERTS/DELETES/UPDATES on some other table, then you can create a trigger for that purpose. But with the simple requirement you gave above without any such dependency, I do not see a need of a trigger here.
If you do have such dependency and need, you have to provide proper requirements with details here.

Insert 1 Million Records 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
I have a simple table 'MyCombs' with 3 columns. ID, Start & End. ID is autoincrement so I have no problem with that. For Start & End points, I have 1million records. These records are different. I have created Insert queries for these 1 miilion records. Now i am facing a problem. When i try to simply run the queries by copying 50,000 records each time in phpMyAdmin, it does not insert these records in table. Loading, Loading. I saw some solution where we have to create a sql format file. I tried but was not able to create such file. Fairly saying, i am completely new to this. Is there anyway i can insert these records into table??
You can achieve it by using 'Bulk Insert' either in MySql or SqlServer !!!
For More Information...refer the following link..
https://dev.mysql.com/doc/refman/5.5/en/optimizing-innodb-bulk-data-loading.html

MYSQL unique VS php SELECT then insert.. Which is faster? [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 8 years ago.
Improve this question
Which is faster If I want to maintain a unique field in a table
Running a select query then insert query
OR directly running an insert query but have a unique field in the table instead
If you want to maintain a unique column in a database, then use the database mechanisms for that. Create a unique index or unique constraint on the column. Work with the database, not against it.
Furthermore, there is a major issue with your first approach. You are introducing a race condition. Two processes could attempt to insert the same record at the same time. They would both look at the values in the table and both would see that the insert is okay. And then both would insert the same value, creating a duplicate.
Of course, there are work-arounds for this, generally involving transactional logic or locking the tables. Both of these introduce additional overhead, which slows down performance.
Just create a unique column and don't worry about the uniqueness -- the database does the worrying for you.

Efficiency of Select query [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 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).

can I retrieve Data as array from MySQL? [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 8 years ago.
Improve this question
I have a two table first is simple primary key based table and second table is keyvaluepair for maintaining records.
Now I want to get records from Table in a single object. If they come as comma separate it's good.
Suppose I have table
ID valueID.
When I will run select query I not want a list of rows. I want a single column (in a row) that I can get the information about all valueIds.
Could someone explain me how can I get them in one instead of list?
You probably want to use GROUP_CONCAT.
SELECT GROUP_CONCAT(valueID) FROM table
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat
If you need both the ID and the valueID, you're better off sticking with an array.