ALT Linux Sisyphus discussions
 help / color / mirror / Atom feed
From: "Денис Смирнов" <mithraen@freesource.info>
To: ALT Linux Sisyphus discussions <sisyphus@lists.altlinux.org>
Subject: Re: [sisyphus] postgresql index row
Date: Fri, 12 Nov 2010 19:39:23 +0300
Message-ID: <20101112163923.GA2748@mw.mithraen.ru> (raw)
In-Reply-To: <AANLkTim=dPg4LhWfr2a=-6FoANQyiq2GL3AAxyg6jEB2@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2122 bytes --]

On Fri, Nov 12, 2010 at 06:06:59PM +0200, Igor Zubkov wrote:

IZ> Вот что бы такой запрос к БД работал быстро, а не как сейчас...
IZ> ree-1.8.7-2010.02 > Changelog.where('changelogtext LIKE \'%CVE%\'').count
IZ>  => 4288
IZ> ree-1.8.7-2010.02 >

Он не будет работать быстрее. Ибо индексы помогают только для поиска
_префикса_. LIKE 'ABC%' -- использует индексы, а LIKE '%CVE%' -- увы, не
испоьлзуют.

IZ>>> ==  AddIndexOnChangelogtext: migrating ========================================
IZ>>> -- add_index(:changelogs, :changelogtext)
IZ>> Ну во первых и впрямь, "а нахрена?!".
IZ> Для быстрого поиска.

Индесы это не просто "штука чтобы искать все было быстрее". Если бы было
так -- просто создавали бы индексы на все колонки и радовались бы жизни :)

Это штука, которая поможет искать быстрее, если применяется правильно.
"Правильно" очень часто это изменение структуры базы, а не просто создание
нужных индексов.

>> Даже если бы это работало -- это было бы все равно ужасно. Опиши какую
>> задачу ты хочешь решить этим странным действием, и тогда тебе подскажут
>> как ее решить красиво.
IZ> Дано много-примного записей из changelog'ов пакетов. Примерно:
IZ> ree-1.8.7-2010.02 >   Changelog.count(:all)
IZ>  => 690859
IZ> ree-1.8.7-2010.02 >
IZ> Столько :)
IZ> Охота вытаскивать из этой кучи только те в которых есть упоминание о
IZ> CVE. Без индекса это просто медленно. Индекс не делается.
IZ> Вот думаю, а не воткнуть ли туда sphinx? Или как бы ещё решить такую задачку.

На этапе импортирования %chanelog в базу вытаскивать эти самые CVE. И
класть в отдельную табличку с полями -- CVE,package,version

к ней два индекса -- один по CVE, другой по паре package,version.

version, разумеется, не в смысле %version, а полностью -- включая serial и
release.

Если нам приходится часто выполнять какой-то сложный запрос -- его не надо
оптимизировать. Надо его ликвидировать, а предварительно заготовленный
результат держать в отдельной табличке.

-- 
С уважением, Денис

http://mithraen.ru/
----------------------------------------------------------------------------

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  parent reply	other threads:[~2010-11-12 16:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-12  2:05 Igor Zubkov
2010-11-12  7:47 ` Alexey I. Froloff
2010-11-12 16:06   ` Igor Zubkov
2010-11-12 16:25     ` Alexey I. Froloff
2010-11-12 16:44       ` Денис Смирнов
2010-11-12 16:39     ` Денис Смирнов [this message]
2010-11-13  6:23       ` Alex Gorbachenko
2010-11-13  8:49         ` Денис Смирнов
2010-11-13 10:07         ` Ivan Fedorov
2010-11-12  9:58 ` Ivan Fedorov
2010-11-12 10:48 ` Денис Смирнов
2010-11-12 12:25   ` [sisyphus] [JT] " Ivan Fedorov
2010-11-13  4:31     ` REAL

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101112163923.GA2748@mw.mithraen.ru \
    --to=mithraen@freesource.info \
    --cc=sisyphus@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Sisyphus discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/sisyphus/0 sisyphus/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 sisyphus sisyphus/ http://lore.altlinux.org/sisyphus \
		sisyphus@altlinux.ru sisyphus@altlinux.org sisyphus@lists.altlinux.org sisyphus@lists.altlinux.ru sisyphus@lists.altlinux.com sisyphus@linuxteam.iplabs.ru sisyphus@list.linux-os.ru
	public-inbox-index sisyphus

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.sisyphus


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git