我有这个MySQL查询,语法是正确的,但是当我想看到视图时,mysql进程会转到100%。
CREATE OR REPLACE VIEW tx_oriconvenios_consultas AS
SELECT conv.*, tipo.descripcion AS tipo_convenio, uni.nombre AS n_universidad, ciu.nombre AS n_ciudad, pais.cn_short_es AS n_pais, COUNT(hist.estado) AS n_estado
FROM tx_unalori_convenio AS conv
LEFT JOIN tx_unalori_historico as hist
ON conv.uid = hist.convenio
INNER JOIN tx_unalori_tipoconv as tipo
ON conv.tipoconv = tipo.uid
INNER JOIN tx_unalori_universidad as uni
ON conv.universidad = uni.uid
INNER JOIN tx_unalori_ciudad as ciu
ON ciu.uid=uni.uid_ciudad
INNER JOIN static_countries as pais
ON pais.cn_iso_3 = ciu.pais
GROUP BY conv.uid
如果我删除:
INNER JOIN static_countries as pais
ON pais.cn_iso_3 = ciu.pais
或:
LEFT JOIN tx_unalori_historico as hist
ON conv.uid = hist.convenio
然后我可以进入视图并查看寄存器。
我无法理解为什么。
我真的赞成一些解释。
对于那些问过的人,这是static_countries的结构:
CREATE TABLE IF NOT EXISTS `static_countries` (
`uid` int(11) unsigned NOT NULL AUTO_INCREMENT,
`pid` int(11) unsigned DEFAULT '0',
`deleted` tinyint(4) NOT NULL DEFAULT '0',
`cn_iso_2` char(2) DEFAULT '',
`cn_iso_3` char(3) DEFAULT '',
`cn_iso_nr` int(11) unsigned DEFAULT '0',
`cn_parent_tr_iso_nr` int(11) unsigned DEFAULT '0',
`cn_official_name_local` varchar(128) DEFAULT '',
`cn_official_name_en` varchar(128) DEFAULT '',
`cn_capital` varchar(45) DEFAULT '',
`cn_tldomain` char(2) DEFAULT '',
`cn_currency_iso_3` char(3) DEFAULT '',
`cn_currency_iso_nr` int(10) unsigned DEFAULT '0',
`cn_phone` int(10) unsigned DEFAULT '0',
`cn_eu_member` tinyint(3) unsigned DEFAULT '0',
`cn_address_format` tinyint(3) unsigned DEFAULT '0',
`cn_zone_flag` tinyint(4) DEFAULT '0',
`cn_short_local` varchar(70) DEFAULT '',
`cn_short_en` varchar(50) DEFAULT '',
`cn_uno_member` tinyint(3) unsigned DEFAULT '0',
`cn_short_es` varchar(50) NOT NULL DEFAULT '',
PRIMARY KEY (`uid`),
UNIQUE KEY `uid` (`uid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=250 ;
这是tx_unalori_historico:
CREATE TABLE IF NOT EXISTS `tx_unalori_historico` (
`uid` int(11) NOT NULL AUTO_INCREMENT,
`pid` int(11) NOT NULL DEFAULT '0',
`tstamp` int(11) NOT NULL DEFAULT '0',
`crdate` int(11) NOT NULL DEFAULT '0',
`cruser_id` int(11) NOT NULL DEFAULT '0',
`deleted` tinyint(4) NOT NULL DEFAULT '0',
`hidden` tinyint(4) NOT NULL DEFAULT '0',
`be_users` int(11) NOT NULL DEFAULT '0',
`convenio` int(11) NOT NULL DEFAULT '0',
`estado` int(11) NOT NULL DEFAULT '0',
`observaciones` text NOT NULL,
PRIMARY KEY (`uid`),
KEY `parent` (`pid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3810 ;
答案 0 :(得分:1)
谢谢@ypercube。
解决问题的方法是将索引键添加到static_countries.cn_iso_3和tx_unalori_ciudad.pais