Обсуждение: Categories and subcategories : more details

Поиск
Список
Период
Сортировка

Categories and subcategories : more details

От
"Rachel Coin"
Дата:
> I have two tables : the first for categories and the second for
> subcategories.I want to get a result like Yahoo! For each category ,
> the sql
> query must return maximum 3 subcategories. I can't use "limit" in a
> subquery
> because I use Postgresql 7.0.

Examples : 

table CATEG :
ida     categ1        X2        Y3        Z 

table SUBCATEG :
idb     subcateg      ida
1           x1             1
2           x2             1
3           x3             1
4           x4             1
5           y1             2
6           y2             2
7           z1             3

I 'd like to obtain a table with maximum 2 subcateg per categ :

table result :

categ     subcateg X           x1 X           x2 Y           y1 Y           y2 Z           z1


any help?

Regards,


Rachel



Re: Categories and subcategories : more details

От
Josh Berkus
Дата:
Rachel,
See below:

> Examples :
> 
> table CATEG :
> ida     categ
>  1        X
>  2        Y
>  3        Z
> 
> table SUBCATEG :
> idb     subcateg      ida
> 1           x1             1
> 2           x2             1
> 3           x3             1
> 4           x4             1
> 5           y1             2
> 6           y2             2
> 7           z1             3
> 
> I 'd like to obtain a table with maximum 2 subcateg per categ :
> 
> table result :
> 
> categ     subcateg
>   X           x1
>   X           x2
>   Y           y1
>   Y           y2
>   Z           z1
> 
Without LIMIT in subselects, you're in performance hell as far as doing
the above is concerned.  Frankly, I can't see any way to do it that
doesn't involve a PL/pgSQL procedure that generates a temporary table,
and has to run once for every row in your result set.  I'll post code
later if nobody comes up with a better solution.
If you knew all of your categories in advance, you could do this via an
annoying UNION statement.  I'm assuming, however, that it needs to be
dynamic.

-Josh Berkus


-- 
______AGLIO DATABASE SOLUTIONS___________________________                                       Josh Berkus  Complete
informationtechnology      josh@agliodbs.com   and data management solutions       (415) 565-7293  for law firms, small
businesses      fax  621-2533   and non-profit organizations.       San Francisco
 


I cannot vacuum

От
Jie Liang
Дата:
Hi,

I have a problem today when I vacuum one table which is vacuumed every
today, I tried re_create index also, didn't work.


urldb=# VACUUM VERBOSE ANALYZE id;
NOTICE:  Vacuum: table not found
VACUUM
urldb=# VACUUM VERBOSE ANALYZE ip;
NOTICE:  --Relation ip--
NOTICE:  Pages 4373: Changed 0, reaped 151, Empty 0, New 0; Tup 662929:
Vac 164, Keep/VTL 0/0, Crash 0, UnUsed 23401, MinLen 48, MaxLen 48;
Re-using: Free/Avail. Space 1137624/0; EndEmpty/Avail. Pages 150/0. CPU
0.33s/2.28u sec.
NOTICE:  Index ip_ip: Pages 2093; Tuples 662929: Deleted 0. CPU
0.15s/0.73u sec.
NOTICE:  Index ip_id: Pages 1311; Tuples 662929: Deleted 0. CPU
0.11s/0.70u sec.
NOTICE:  Rel ip: Pages: 4373 --> 4223.
NOTICE:  FlushRelationBuffers(ip, 4223): block 4365 is referenced (private
0, global 8)
FATAL 1:  VACUUM (vc_vacheap): FlushRelationBuffers returned -2
pqReadData() -- backend closed the channel unexpectedly.
    This probably means the backend terminated abnormally
    before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.

any suggestion??

Jie LIANG

St. Bernard Software

10350 Science Center Drive
Suite 100, San Diego, CA 92121
Office:(858)320-4873

jliang@ipinc.com
www.stbernard.com
www.ipinc.com



Re: I cannot vacuum

От
Tom Lane
Дата:
Jie Liang <jliang@ipinc.com> writes:
> NOTICE:  FlushRelationBuffers(ip, 4223): block 4365 is referenced (private
> 0, global 8)
> FATAL 1:  VACUUM (vc_vacheap): FlushRelationBuffers returned -2

Try restarting your postmaster.

            regards, tom lane

Re: [ADMIN] Re: I cannot vacuum

От
Jie Liang
Дата:
Tom,

NOTICE:  --Relation ip--
NOTICE:  Pages 4244: Changed 1, reaped 13, Empty 0, New 0; Tup 665627: Vac
32, Keep/VTL 0/0, Crash 0, UnUsed 594, MinLen 48, MaxLen 48; Re-using:
Free/Avail. Space 33168/26016; EndEmpty/Avail. Pages 0/12. CPU 0.32s/2.26u
sec.
NOTICE:  Index ip_ip: Pages 3204; Tuples 665627: Deleted 13. CPU
0.20s/0.80u sec.
NOTICE:  Index ip_id: Pages 1499; Tuples 665627: Deleted 13. CPU
0.04s/0.81u sec.
NOTICE:  Rel ip: Pages: 4244 --> 4240; Tuple(s) moved: 13. CPU 0.00s/0.00u
sec.
NOTICE:  Index ip_ip: Pages 3204; Tuples 665627: Deleted 13. CPU
0.19s/0.79u sec.
NOTICE:  Index ip_id: Pages 1499; Tuples 665627: Deleted 13. CPU
0.09s/0.74u sec.
NOTICE:  FlushRelationBuffers(ip, 4240): block 4242 is referenced (private
0, global 1)
FATAL 1:  VACUUM (vc_repair_frag): FlushRelationBuffers returned -2
pqReadData() -- backend closed the channel unexpectedly.
    This probably means the backend terminated abnormally
    before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.

This happen again today,
urldb=# select version();
                                 version
-------------------------------------------------------------------------
 PostgreSQL 7.0.0 on i386-unknown-freebsdelf3.4, compiled by gcc 2.7.2.3

Dose later version such as 7.0.3 resolved this problem??

if so, which version I should install?



Jie LIANG

St. Bernard Software

10350 Science Center Drive
Suite 100, San Diego, CA 92121
Office:(858)320-4873

jliang@ipinc.com
www.stbernard.com
www.ipinc.com

On Tue, 20 Mar 2001, Tom Lane wrote:

> Jie Liang <jliang@ipinc.com> writes:
> > NOTICE:  FlushRelationBuffers(ip, 4223): block 4365 is referenced (private
> > 0, global 8)
> > FATAL 1:  VACUUM (vc_vacheap): FlushRelationBuffers returned -2
>
> Try restarting your postmaster.
>
>             regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>


Re: [ADMIN] Re: I cannot vacuum

От
Tom Lane
Дата:
Jie Liang <jliang@ipinc.com> writes:
> Dose later version such as 7.0.3 resolved this problem??

Possibly.  Try it and see.  You should be running 7.0.3 anyway,
just on general principles.

            regards, tom lane