Chinaunix首页 | 论坛 | 博客
  • 博客访问: 75455
  • 博文数量: 15
  • 博客积分: 305
  • 博客等级: 二等列兵
  • 技术积分: 140
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-10 11:42
文章分类

全部博文(15)

文章存档

2013年(2)

2012年(7)

2011年(1)

2010年(1)

2009年(4)

我的朋友

分类: Mysql/postgreSQL

2010-04-01 13:24:38

临时表使用 产品top like语法优化

根据活动信息表取top10,第二次优化,执行速度0.097ms。

总记录行数:43479

CREATE DEFINER=`root`@`localhost` PROCEDURE `yuyu`(in INPHONEMODNO varchar(10),in INBigTypeID varchar(10), in INNotDisplaySupcode varchar(800))
begin

DROP TEMPORARY TABLE IF EXISTS tb_tmp_topprod;

CREATE TEMPORARY TABLE tb_tmp_topprod (
    id INT AUTO_INCREMENT PRIMARY KEY,
    ProdCode varchar(14) collate utf8_unicode_ci NOT NULL,
    ProdName varchar(100) collate utf8_unicode_ci default NULL,
    ProdEName varchar(100) collate utf8_unicode_ci default NULL,
    PRODSPELL varchar(100) collate utf8_unicode_ci default NULL,
    ThirdTypeID varchar(100) collate utf8_unicode_ci default NULL,
    ThirdTypeName varchar(100) collate utf8_unicode_ci default NULL,
    ThirdTypeEName varchar(100) collate utf8_unicode_ci default NULL,
    ThirdTypeImg varchar(100) collate utf8_unicode_ci default NULL,
    SupCode varchar(100) collate utf8_unicode_ci default NULL,
    FILEPATH varchar(400) collate utf8_unicode_ci default NULL,
    FILESIZE BIGINT,
    ProdImg varchar(100) collate utf8_unicode_ci default NULL,
    ProdMovie varchar(100) collate utf8_unicode_ci default NULL,
    ProdPrice decimal(18,4) default NULL,
    Integral int,
    ZY varchar(800) collate utf8_unicode_ci default NULL,
  FULLTEXT KEY `ProdNameIndex` (`ProdName`)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

if INNotDisplaySupcode<>'' then
    if INBigTypeID in('04','07') then
        INSERT INTO tb_tmp_topprod( ProdCode,ProdName,ProdEName,PRODSPELL,ThirdTypeID,ThirdTypeName,ThirdTypeEName,ThirdTypeImg,SupCode,FILEPATH,FILESIZE,ProdImg,ProdMovie,ProdPrice,Integral,ZY)
        select a.ProdCode,a.ProdName,a.ProdEName,a.PRODSPELL,a.ThirdTypeID,a.ThirdTypeName,a.ThirdTypeEName,a.ThirdTypeImg,a.SupCode,a.FILEPATH,a.FILESIZE,a.ProdImg,a.ProdMovie,a.ProdPrice,0 as Integral,a.ZY from xa_dg_prodinfo a where CONVERT(a.BigtypeID using utf8)=CONVERT(INBigTypeID using utf8) and convert(a.supcode using utf8) not in (convert(INNotDisplaySupcode using utf8));

else

    -- 省略----------
end if;


if INBigTypeID in('01','02','05') then
select a.ProdCode,a.ProdName,a.ProdEName,a.PRODSPELL,a.SupCode,a.FILEPATH,a.FILESIZE,a.ProdImg,a.ProdMovie,a.ProdPrice,a.Integral,a.ZY,b.tag from tb_tmp_topprod a
left join xa_dg_prod_activeprodlist b on b.Tag='TOP' and instr(a.prodname,b.prodname)>0 order by b.tag desc,b.ID asc limit 0,10;
end if;-- 删除临时表

DROP TEMPORARY TABLE IF EXISTS tb_tmp_topprod;
END


 

阅读(919) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~