Re: Index not used with IS NULL

Поиск
Список
Период
Сортировка
От Dima Tkach
Тема Re: Index not used with IS NULL
Дата
Msg-id 3E4FF67D.9050003@openratings.com
обсуждение исходный текст
Ответ на Re: Index not used with IS NULL  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
>>A row in the table is a tree node. A node can have one parent, ot no
>>parent at all.
>
>
> You're better off making the root node link to itself (compare handling
> of /.. in a Unix filesystem).  NULL parent link does not mean "has no
> parent", it means "parent is unknown".
>

Great idea! I'll do that. Thanks!
What about another example:

create table user
(
    id serial primary key,
    login text not null unique
);

create table tag_set
(
    id     serial primay key,
    tag    text not null unique,
    data   text not null,
    userid int references users on delete cascade on update cascade
);

The idea is that 'tags' may be user-specific or user-independent - so
that to get a set of tags for a given user, I would do

select tag,data from tag_set where userid is null or userid=?

with my 'workaround' solution I do
select tag,data from tag_set where userid==null or userid=?
(where '==' is my special non-strict operator)
to force both parts of the criteria to use the index

Any ideas how to do this better (again, other than creating a dummy user
with id 0)?

I'll apppreciate any suggestions...

Thanks a lot!

Dima





В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Aggregates with non-commutative transition functions
Следующее
От: Oliver Elphick
Дата:
Сообщение: Re: inheritance