LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-21-2014, 10:51 AM   #1
ubungu
LQ Newbie
 
Registered: Jun 2012
Location: /home/ubungu
Posts: 27

Rep: Reputation: Disabled
Smile How can I index field in this case


Hi all

I have table 'users' with 200K rows. It have 20 fields.

Some fields in query are:
life: int(11)
last_increase: int(11)
max_life: enum('0','1')

I have query:

Code:
UPDATE `users` SET `life` = CASE
                WHEN `life` >= 0 AND `life` < 5 AND `last_increase` <= (1390320962 - 900)
                THEN (`life` + 1)
                ELSE `life`
                END,
                `last_increase` =
                CASE
                WHEN `life` >= 0 AND `life` < 6 AND `last_increase` <= (1390320962 - 900)
                THEN (1390320962)
                ELSE `last_increase`
                END
                WHERE max_life = '0';

And it take more than 10s to finish ( ~ 11 seconds)

I indexes 'last_increase' field.
Can you tell me how to index fields in this case, and why do you do it.

Thank for your helping
 
Old 01-22-2014, 04:44 AM   #2
ubungu
LQ Newbie
 
Registered: Jun 2012
Location: /home/ubungu
Posts: 27

Original Poster
Rep: Reputation: Disabled
Hi, please help me
 
Old 01-24-2014, 04:11 AM   #3
ubungu
LQ Newbie
 
Registered: Jun 2012
Location: /home/ubungu
Posts: 27

Original Poster
Rep: Reputation: Disabled
Can you help me?
 
Old 01-24-2014, 04:41 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
1. Relax, this is a volunteer site; we answer when we can and if we want to ....

2. Why not use 2 simple updates instead of that
Code:
UPDATE users 
SET life = life + 1
WHERE life >= 0
AND life < 5
AND last_increase` <= (1390320962 - 900) 
AND max_life = 0
;

UPDATE users 
SET last_increase = 1390320962
WHERE life >= 0 
AND life < 6 
AND last_increase <= (1390320962 - 900)
AND max_life = 0
;
Note no need for quoting table/col names unless they are also DB / SQL keywords (not recommended anyway).
Also, I'd pre-calc (1390320962 - 900) before using it; definitely speeds things up.
You could also index life col.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Count occurrence of character in field and print in a new field Trd300 Linux - Newbie 5 03-21-2012 07:57 PM
LXer: ActiveState Launches Python Package Manager Index (PyPM Index) LXer Syndicated Linux News 0 11-03-2010 03:40 PM
How to change the default webpage configuration from index.php to index.htm, etc meema Linux - Server 4 08-22-2008 09:06 PM
apache index.html doesn't show up but index.php do zoffmann Linux - Server 5 01-28-2008 03:53 PM
Where to put index.php (or index.html) on Slackware 11.0 moonguide Slackware 3 05-08-2007 06:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration