一条SQL查询语句的优化(效率提升1000倍)

admin 提交于 周二, 05/19/2015 - 11:57

weike_student_wrong_questions表大概有150万行数据,其中(tid, cid)做了索引,weike_exam_files不到100行,tid做了索引。下面一条语句执行时间大概是1.3秒。

 

SELECT weike_student_wrong_questions.tid, name, exam_time,
update_time, cid
FROM weike_student_wrong_questions
INNER JOIN weike_exam_files
ON weike_student_wrong_questions.tid = weike_exam_files.tid
GROUP BY weike_student_wrong_questions.tid, cid
ORDER BY exam_time DESC, cid;

把语句换成下面之后,查询效率大概提高了1000倍。 

     

标签

Ubuntu怎样安装Drush

admin 提交于 周一, 05/18/2015 - 10:07

 

apt-get update

apt-get install curl

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

ln -s /usr/local/bin/composer /usr/bin/composer

composer global require drush/drush:dev-master

apt-get install git

git clone https://github.com/drush-ops/drush.git /usr/local/src/drush

mv /usr/bin/drush /usr/bin/drush.old

ln -s /usr/local/src/drush/drush /usr/bin/drush

cd /usr/local/src/drush

composer install

标签

RANKING IN MYSQL RESULTS

admin 提交于 周四, 05/14/2015 - 10:18

A friend of me asked me long time ago: "How can I have a ranking on a result with MySQL?". Now I found some time to write it down:

Lets do first some preparation for the example:

CREATE TABLE sales (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
, fruit VARCHAR(32)
, amount DECIMAL
);

INSERT INTO sales
VALUES (NULL, 'apple', 12.75), (NULL, 'orange', 1.89), (NULL, 'pear', 19.23)
, (NULL, 'banana', 4.25), (NULL, 'cherry', 123.75), (NULL, 'plum', 23.15)
;

Now lets query:

标签