与其他表的索引关系

问题描述

我有一个像这样的桌子:

MysqL> SHOW CREATE TABLE lz_stats_aggs\G
*************************** 1. row ***************************
       Table: lz_stats_aggs
Create Table: CREATE TABLE `lz_stats_aggs` (
  `year` smallint(4) unsigned NOT NULL DEFAULT '0',`month` tinyint(3) unsigned NOT NULL DEFAULT '0',`day` tinyint(3) unsigned NOT NULL DEFAULT '0',`time` int(10) unsigned NOT NULL DEFAULT '0',`mtime` int(10) unsigned NOT NULL DEFAULT '0',`sessions` int(10) unsigned NOT NULL DEFAULT '0',`visitors_unique` int(10) unsigned NOT NULL DEFAULT '0',`conversions` int(10) unsigned NOT NULL DEFAULT '0',`aggregated` int(10) unsigned NOT NULL DEFAULT '0',`chats_forwards` int(10) unsigned NOT NULL DEFAULT '0',`chats_posts_internal` int(10) unsigned NOT NULL DEFAULT '0',`chats_posts_external` int(10) unsigned NOT NULL DEFAULT '0',`avg_time_site` double unsigned NOT NULL DEFAULT '0',PRIMARY KEY (`year`,`month`,`day`),KEY `time` (`time`),KEY `aggregated` (`aggregated`),KEY `mtime` (`mtime`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin
1 row in set (0.00 sec)



MysqL> describe lz_stats_aggs;
+----------------------+----------------------+------+-----+---------+-------+
| Field                | Type                 | Null | Key | Default | Extra |
+----------------------+----------------------+------+-----+---------+-------+
| year                 | smallint(4) unsigned | NO   | PRI | 0       |       |
| month                | tinyint(3) unsigned  | NO   | PRI | 0       |       |
| day                  | tinyint(3) unsigned  | NO   | PRI | 0       |       |
| time                 | int(10) unsigned     | NO   | MUL | 0       |       |
| mtime                | int(10) unsigned     | NO   | MUL | 0       |       |
| sessions             | int(10) unsigned     | NO   |     | 0       |       |
| visitors_unique      | int(10) unsigned     | NO   |     | 0       |       |
| conversions          | int(10) unsigned     | NO   |     | 0       |       |
| aggregated           | int(10) unsigned     | NO   | MUL | 0       |       |
| chats_forwards       | int(10) unsigned     | NO   |     | 0       |       |
| chats_posts_internal | int(10) unsigned     | NO   |     | 0       |       |
| chats_posts_external | int(10) unsigned     | NO   |     | 0       |       |
| avg_time_site        | double unsigned      | NO   |     | 0       |       |
+----------------------+----------------------+------+-----+---------+-------+
13 rows in set (0.00 sec)

我还有其他几张表具有相同的天,月和年字段作为主键。 现在,我需要将表中的数据插入到今天的17/7/2020。 但是,当我这样做时,会出现错误

MysqL> LOAD DATA INFILE '/var/opt/rh/rh-MysqL57/lib/MysqL-files/lz_stats_aggs07.csv' INTO TABLE lz_stats_aggs FIELDS TERMINATED BY ',';
ERROR 1062 (23000): Duplicate entry '2020-7-20' for key 'PRIMARY'

当我检查表格中17日之后的日期时,我得到了:

MysqL> select * from lz_stats_aggs where day >= '16' and month = '7' and year = '2020';
+------+-------+-----+------------+----------+----------+-----------------+-------------+------------+----------------+----------------------+----------------------+---------------+
| year | month | day | time       | mtime    | sessions | visitors_unique | conversions | aggregated | chats_forwards | chats_posts_internal | chats_posts_external | avg_time_site |
+------+-------+-----+------------+----------+----------+-----------------+-------------+------------+----------------+----------------------+----------------------+---------------+
| 2020 |     7 |  16 | 1595235228 |  3557100 |      416 |             416 |           0 | 1595235227 |              0 |                  982 |                  987 |     1316.7668 |
| 2020 |     7 |  17 | 1595005244 | 10273000 |      409 |             408 |           0 | 1595005243 |              0 |                  719 |                  614 |     2075.2298 |
| 2020 |     7 |  18 | 1595091680 | 49116400 |        0 |               0 |           0 | 1595091680 |              0 |                    0 |                    0 |             0 |
| 2020 |     7 |  19 | 1595178102 | 97573600 |        1 |               1 |           0 | 1595178102 |              0 |                    0 |                    0 |          7859 |
| 2020 |     7 |  20 | 1595385572 | 99382700 |        0 |               0 |           0 | 1595385572 |              0 |                    0 |                    0 |             0 |
| 2020 |     7 |  24 | 1595670196 | 56234500 |        0 |               0 |           0 | 1595670196 |              0 |                    0 |                    0 |             0 |
| 2020 |     7 |  25 | 1597584414 |  1487900 |        0 |               0 |           0 | 1597584413 |              0 |                    0 |                    0 |             0 |
+------+-------+-----+------------+----------+----------+-----------------+-------------+------------+----------------+----------------------+----------------------+---------------+
7 rows in set (0.00 sec)

我的问题是,如果我删除这些行,它将如何影响该数据库中的其他表? “关键”项目的功能是什么,例如时间,合计和mtime?删除这些行会在其他表中引起问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)