Sppidy
Sppidy

Reputation: 433

mysql update query takes too long

i have a table with 2255440 records,

a cron job works every minute and inserts upto 50-100 records on every execution

inserts are working fine

the problem is that there is another cron job which is also running every minute.. this cron job updates these records according to the data recieved from other server

the problem is that the update query is taking around 6 - 7 seconds per update query

this is the table information and update query example

enter image description here

enter image description here

enter image description here

records are updated with this query

Query:

UPDATE `$month`
SET `acctstoptime`='$data->acctstoptime',
    `acctsessiontime`='$data->acctsessiontime',
    `acctinputoctets`='$data->acctinputoctets',
    `acctoutputoctets`='$data->acctoutputoctets',
    `acctterminatecause`='$data->acctterminatecause'
WHERE `radacctid`=$data->radacctid

Upvotes: 0

Views: 274

Answers (2)

Vikram Jain
Vikram Jain

Reputation: 5588

CREATE INDEX:

Indexes are used to retrieve data from the database more quickly than otherwise. The users cannot see the indexes, they are just used to speed up searches/queries.

Syntax:

CREATE INDEX [index name] ON [table name]([column name]);

Arguments

Name            Description

index name      Name of the index.
table name      Name of the table.
column name     Name of the column.

Example

Code:

CREATE  INDEX radacctid ON table_name(radacctid);

Upvotes: 0

kobako
kobako

Reputation: 673

Is there a single-column index on column of 'radacctid'?

If not you should create one.

Upvotes: 1

Related Questions