如何选择多个条件并在大表中快速加入

时间:2016-10-22 15:48:53

标签: mysql full-text-search

我有一个相当大的表(新闻文章表)(~6 GB),这个表每天都要大一点。

我想根据用户参数集在此表中搜索。

我的搜索基于类别,代理商,注册时间和用户输入的字词。

用户搜索时

单词:“مذاکراتهستهای”

Cat:2

代理商:1

注册时间:1426883460

我写这个查询:

CREATE TABLE IF NOT EXISTS `news` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) COLLATE utf8_persian_ci NOT NULL,
  `link` varchar(500) COLLATE utf8_persian_ci NOT NULL,
  `des` varchar(500) COLLATE utf8_persian_ci NOT NULL,
  `tag` varchar(250) COLLATE utf8_persian_ci NOT NULL,
  `img` varchar(400) COLLATE utf8_persian_ci NOT NULL,
  `type` int(11) NOT NULL,
  `agency` int(11) NOT NULL,
  `time` int(11) NOT NULL,
  `regTime` int(11) NOT NULL,
  `view` int(11) NOT NULL,
  `like` int(11) NOT NULL,
  `disslike` int(11) NOT NULL,
  `point` int(11) NOT NULL,
  `cat` int(11) NOT NULL,
  `mytag` varchar(250) COLLATE utf8_persian_ci NOT NULL,
  `top` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `cat` (`cat`),
  KEY `agency` (`agency`),
  FULLTEXT KEY `mytag` (`mytag`),
  FULLTEXT KEY `tag` (`tag`),
  FULLTEXT KEY `title` (`title`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci;

现在这个查询在我的表中很慢,我相信它会慢一些。

我可以做些什么来加快搜索速度?

更新:表架构

新闻表:

CREATE TABLE IF NOT EXISTS `site_cat` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(30) COLLATE utf8_persian_ci NOT NULL,
  PRIMARY KEY (`id`),
  KEY `id` (`id`),
  FULLTEXT KEY `title` (`title`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci

site_cat表:

CREATE TABLE IF NOT EXISTS `newsagency` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(250) COLLATE utf8_persian_ci NOT NULL,
  `link` varchar(500) COLLATE utf8_persian_ci NOT NULL,
  `topLink` varchar(250) COLLATE utf8_persian_ci NOT NULL,
  `sort` int(11) NOT NULL,
  `img` varchar(250) COLLATE utf8_persian_ci NOT NULL,
  `view` int(11) NOT NULL,
  `des` varchar(100) COLLATE utf8_persian_ci NOT NULL,
  `story` varchar(100) COLLATE utf8_persian_ci NOT NULL,
  `tag` varchar(100) COLLATE utf8_persian_ci NOT NULL,
  `imgF` varchar(100) COLLATE utf8_persian_ci NOT NULL,
  `url` varchar(250) COLLATE utf8_persian_ci NOT NULL,
  `flag` int(11) NOT NULL,
  `encode` int(1) NOT NULL,
  `persian` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `view` (`view`),
  KEY `sort` (`sort`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci 

newsagency表:

# plugins/TestPlugin/config/menus.php

return [
    'menus' => [
        [
            'header' => 'TestPlugin',
            [
                'title' => 'Click me!',
                'href' => './',
            ],
            [
                'title' => 'Click me too!',
                'href' => './',
            ]
        ]
    ]
];

0 个答案:

没有答案