我创建了一个表,其中有近800,000条记录。
mysql> describe automation_search_test;
+----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL
我在这里有一个非常糟糕的问题,所以希望你们所有的MySQL专家都能为我回答这个问题:)
我有这样一种表:
+--------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------------+------+-----+---------+-------+
| id | int(10) unsigned | NO | PRI | NULL | |
| a
我有一个mysql数据库与myisam引擎。与许多其他表一起,我有这个表"et“,它有大约8137037条记录。
我已经创建了索引(列hname和pnum的单独索引,后来创建hname和pnum的联合索引并没有什么帮助,它有助于在一秒钟内执行),这样的查询如下
select st from et where hname='name' and pnum='1' limit 1
执行速度很快(在一秒钟内),但问题是我必须执行这个查询
select st from et where hname='name' and pnum='1
表结构:
+-------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| total | int(11) |
在从第二个表中排序列时,我无法取消“临时;使用文件”。
explain SELECT *
FROM post
JOIN post_plus
ON post_plus.news_id = post.id
WHERE category regexp '[[:<:]](131|138|139|140|141|142|143|144|145|146|147|148|149|150|151|152|153|154|155|156|157|171|172|134|136|137|23|123)[[:>
我在数据库中有一个表‘post’,它在user_id上有非唯一的索引(键: MUL)。
mysql> show columns from posts;
+---------+--------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+-------------------+--------
我使用的是MySql 8。我想加快表单表上的搜索速度。
select * FROM dirctory_coop where name like '%mystr%';
有人提到使用全文搜索-- https://dev.mysql.com/doc/refman/8.0/en/fulltext-search.html。不过,我对此有意见。下面是我的桌子。
mysql> desc directory_coop;
+----------+--------------+------+-----+---------+----------------+
| Field | Type
我在下面的查询中遇到了麻烦,在添加了ORDER BY kp_votes DESC, kp_rating DESC之后,它变得非常非常慢,问题是我已经为这些列建立了索引。
explain SELECT *
FROM post
JOIN post_plus
ON post_plus.news_id = post.id
WHERE category regexp '[[:<:]](131|138|139|140|141|142|143|144|145|146|147|148|149|150|151|1
我遇到了一个特定的查询速度慢的问题。尽管所有的东西都有大量的索引,一些类似的查询运行良好,并且使用了索引,但查询仍然慢得要死。我不明白为什么,也许任何人都能帮上忙。
前提条件:底层表的写入速度无关紧要。该表包含大约350万个条目,但我认为MySQL应该可以很好地处理这个问题。
较慢的查询大约需要2秒
SELECT DISTINCT t.`tag_3` FROM `image_tags` t
WHERE t.`type` = 1 AND t.`category` LIKE "00%" AND tag_1 = "0"
--- DESCRIBE OU
假设我有一个数据库,其中有3个表描述了总线时间表:
journey
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL |
mysql> explain SELECT *
-> FROM (`items`)
-> WHERE `states` = 'A'
-> ORDER BY `updated_date` desc
-> LIMIT 20520, 40;
+----+-------------+--------+--------+----------------------------+---------------------+---------+----------+-------+-------------+
| id | sel
我有两个mysql表,其结构如下:
mysql> describe symbol;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI
mysql> desc users;
+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL
我有一张有14000000个帖子的表格。当我使用select语句查询表时,按照postings表的日期时间字段排序,MySQL总是使用文件排序,导致查询时间非常慢(>3秒)。以下是story表的模式(简化):
+---------------------+---------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra
我有以下简单的MySQL查询:
SELECT SQL_NO_CACHE mainID
FROM tableName
WHERE otherID3=19
AND dateStartCol >= '2012-08-01'
AND dateStartCol <= '2012-08-31';
当我运行它时,它需要0.29秒才能返回36074个结果。当我增加我的date period以返回更多的结果(65703)时,它运行在0.56.当我在同一台服务器上对不同的表(有些表更大)运行其他类似的SQL查询时,结果大约在0.01秒内返回。
虽然0.29并不慢-但
原因是什么?在同一DB上,select语句按预期工作:
select id from line where line.id = 298;
但以下delete语句失败:
delete from line where line.id = 298;
有错误:
Unknown column 'line_id' in 'where clause'
查询输出:
mysql> delete from line where line.id = 298;
ERROR 1054 (42S22): Unknown column 'line_id' in '
如何在日期时间字段的日期部分创建索引?
mysql> SHOW COLUMNS FROM transactionlist;
+-------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+------------------+------+-----+---------+----------
这是我正在尝试优化的查询:
SELECT SUM(`backend_ubqstat`.`complementary_revenue`) AS `complementary_revenue__sum`, SUM(`backend_ubqstat`.`revenue`) AS `revenue__sum` FROM `backend_ubqstat`
INNER JOIN `backend_ubq` ON ( `backend_ubqstat`.`ubq_id` = `backend_ubq`.`id` )
WHERE
(`backend_ubqstat`.`store_number` =
我们正在工作的一个新项目需要大量的数据分析,但我们发现这是非常缓慢的,我们正在寻找方法来改变我们的方法与软件和/或硬件。
我们目前在亚马逊ec2实例(Linux)上运行:
High-CPU Extra Large Instance
7 GB of memory
20 EC2 Compute Units (8 virtual cores with 2.5 EC2 Compute Units each)
1690 GB of instance storage
64-bit platform
I/O Performance: High
API name: c1.xlarge
processor
我有一个使用group by和order by的查询,但它非常慢!我需要一些帮助来使索引正确。这是我正在运行的查询:
select *
from puresen_mv_shop.cache_deals
where feature_ids REGEXP 'i,t,d'
and phone_cost > 100.00
group by handset_numeric_id
order by popularity
LIMIT 0,10;
解释:
1 SIMPLE cache_deals index popularity 5 10 663
我的feed_listingjob有两个日期时间字段:
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_incremen
我不知道这个MySQL查询在JPQL中会是什么样子。详情:
select title
from post
order by (
select count(postId)
from comment
where comment.postId=post.id
) desc;
编辑:投递表外观:
mysql> desc post;
+---------------+----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Defau