【发布时间】:2021-09-26 19:42:01
【问题描述】:
Warning: #1292 Truncated incorrect DOUBLE value: "
错误:警告:#1292 截断不正确的 DOUBLE 值:“
我的“视图”的结构如下:
# | Name | Type
1 id1 varchar(255)
2 id2 varchar(255)
3 category1 varchar(255)
4 category2 varchar(255)
5 category3 varchar(255)
6 id2name varchar(255)
7 date1 date
8 date2 date
9 name1 varchar(255)
10 name2 varchar(255)
11 name3 varchar(255)
12 category4 varchar(255)
13 level1 int(11)
14 level2 int(11)
15 levelflex varchar(255)
16 category5 varchar(255)
17 category6 varchar(255)
18 category7 varchar(21)
SQL 代码:
SELECT
`x`.`id1` AS `id1`,
`x`.`id2` AS `id2`,
`x`.`category1` AS `category1`,
`x`.`category2` AS `category2`,
`x`.`category3` AS `category3`,
`x`.`id2name` AS `id2name`,
`x`.`date1` AS `date1`,
`x`.`date2` AS `date2`,
`x`.`name1` AS `name1`,
`x`.`name2` AS `name2`,
`x`.`name3` AS `name3`,
`x`.`category4` AS `category4`,
`x`.`level1` AS `level1`,
`x`.`level2` AS `level2`,
`x`.`levelflex` AS `levelflex`,
`x`.`category5` AS `category5`,
`x`.`category6` AS `category6`,
`x`.`category7` AS `category7`FROM
(
(
SELECT
`r`.`id1` AS `id1`,
`d`.`id2` AS `id2`,
`m`.`subcategory` AS `category1`,
`n`.`subcategory` AS `category2`,
`r`.`category3` AS `category3`,
`d`.`id2name` AS `id2name`,
`r`.`date1` AS `date1`,
`d`.`date2` AS `date2`,
`r`.`name1` AS `name1`,
`r`.`name2` AS `name2`,
`r`.`name3` AS `name3`,
`r`.`category4` AS `category4`,
`r`.`level1` AS `level1`,
`d`.`level1` AS `level2`,
`d`.`level1flex` AS `levelflex`,
`r`.`category5` AS `category5`,
`r`.`category6` AS `category6`,
CAST(
rank() over(
PARTITION BY `r`.`id1`
ORDER BY CASE WHEN
`m`.`subcategory` = `n`.`subcategory` AND `r`.`level1` = `d`.`level1` THEN 1 WHEN `m`.`subcategory` = `n`.`subcategory` AND `r`.`level1` = `d`.`levelflex` THEN 2 WHEN `m`.`subcategory` <> `n`.`subcategory` AND `r`.`level1` = `d`.`level1` THEN 3 WHEN `m`.`subcategory` <> `n`.`subcategory` AND `r`.`level1` = `d`.`levelflex` THEN 4
END,
`d`.`date2`,
`r`.`id1`
) AS CHAR CHARSET utf8mb4) AS `category7`FROM
(
(
(
(
(
(
(
(
`Server`.`table1` `d`
JOIN `Server`.`table2` `r`
ON
(
`d`.`category4` = `r`.`category4` AND(
`d`.`level1` = `r`.`level1` AND `r`.`level1` <> 12 AND `r`.`level1` <> 13 OR SUBSTRING_INDEX(`d`.`levelflex`, ',', 1) = `r`.`level1` AND `r`.`level1` <> 12 AND `r`.`level1` <> 13 OR SUBSTRING_INDEX(`d`.`levelflex`, ',', -1) = `r`.`level1` AND `r`.`level1` <> 12 AND `r`.`level1` <> 13
)
)
)
JOIN `Server`.`table3` `p`
ON
(
`d`.`id2name` = `p`.`newid2name` OR `d`.`id2name` = `p`.`oldid2name`
)
)
JOIN `Server`.`table4` `m`
ON
(
`p`.`newid2name` = `m`.`id2name` OR `p`.`oldid2name` = `m`.`id2name`
)
)
JOIN `Server`.`table5` `h`
ON
(`r`.`category3` = `h`.`category3`)
)
JOIN `Server`.`table6` `f`
ON
(`r`.`id1` = `f`.`id1`)
)
LEFT JOIN `Server`.`table7` `e`
ON
(`f`.`id1` = `e`.`id1`)
)
JOIN `Server`.`table8` `n`
ON
(
(
`r`.`date1` >= `h`.`subdate1` AND `e`.`subdate1` = `h`.`subdate1` OR `f`.`subdate2` = `h`.`subdate1` AND `r`.`date1` < `h`.`subdate1`
) AND `h`.`id2name` = `n`.`id2name`
)
)
LEFT JOIN `Server`.`table9` `z`
ON
(
`d`.`id2` = `z`.`id2` AND `r`.`id1` = `z`.`id1`
)
)
WHERE
`z`.`id2` IS NULL
) `x`LEFT JOIN `Server`.`table10` `y`ON
(
`x`.`id2` = `y`.`id2` AND `x`.`id1` = `y`.`id1`
)
)WHERE
`y`.`id2` IS NULL
总共 44 行的查询也需要大约 15 秒或更长时间。有什么办法可以优化吗?
我也在尝试将数据从视图传输到表。对此有何建议?
显示创建表:
| View | Create View | character_set_client | collation_connection |
|---|---|---|---|
| sampleview | CREATE ALGORITHM=UNDEFINED DEFINER=dbadmin@%SQL SECURITY DEFINER VIEWsampleviewAS selectx.id1 AS id1,x.`r... |
utf8mb4 | utfmb4_unicode_ci |
解释选择...:
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|---|---|---|---|---|---|---|---|---|---|
| 1 | PRIMARY | derived2 | ALL | NULL | NULL | NULL | NULL | 251497948917600 | |
| 1 | PRIMARY | y | ALL | NULL | NULL | NULL | NULL | 1 | Using where; Using join buffer(flat, BNL join) |
| 2 | DERIVED | d | ALL | NULL | NULL | NULL | NULL | 106 | Using temporary |
| 2 | DERIVED | f | ALL | PRIMARY | NULL | NULL | NULL | 115 | Using join buffer(flat,BNL join) |
| 2 | DERIVED | e | eq_ref | PRIMARY | PRIMARY | 767 | Server.f.id1 | 1 | |
| 2 | DERIVED | r | eq_ref | PRIMARY | PRIMARY | 767 | Server.f.id1 | 1 | Using where |
| 2 | DERIVED | z | ALL | NULL | NULL | NULL | NULL | 1 | Using where; Using join buffer (flat, BNL join) |
| 2 | DERIVED | p | ALL | NULL | NULL | NULL | NULL | 140 | Using where; Using join buffer (incremental, BNL join) |
| 2 | DERIVED | m | ALL | NULL | NULL | NULL | NULL | 198 | Using where; Using join buffer (incremental, BNL join) |
| 2 | DERIVED | n | ALL | NULL | NULL | NULL | NULL | 198 | Using join buffer (flat, BNL join) |
| 2 | DERIVED | h | ALL | NULL | NULL | NULL | NULL | 3759 | Using where; Using join buffer (incremental, BNL join) |
【问题讨论】:
-
编辑以包含完整的 SQL,以及作为文本的完整错误消息。