Subject Garbage, was Re: [firebird-support] SubSelect problems
Author jasajona
> What indexes do you have on those three tables? What is the
> selectivity of those indexes - use gstat to check.

Today I cannot reproduce that performace slowdown. Probably I missed a
condition that made server work slow. Have a look, maybe you will see
something bad her:

Database header page information:
Flags 0
Checksum 12345
Generation 1566
Page size 4096
ODS version 10.1
Oldest transaction 1509
Oldest active 1510
Oldest snapshot 1473
Next transaction 1558
Bumped transaction 1
Sequence number 0
Next attachment ID 0
Implementation ID 19
Shadow count 0
Page buffers 0
Next header page 0
Database dialect 3
Creation date Jan 12, 2005 11:39:43
Attributes

Variable header data:
Sweep interval: 20000
*END*


Database file sequence:
File vandenai.gdb is the only file

Database log page information:
Creation date
Log flags: 2
No write ahead log

Next log page: 0

Variable log data:
Control Point 1:
File name:
Partition offset: 0 Seqno: 0 Offset: 0
Control Point 2:
File name:
Partition offset: 0 Seqno: 0 Offset: 0
Current File:
File name:
Partition offset: 0 Seqno: 0 Offset: 0
*END*

==================================

DOKUMENTUDETALIZACIJOS (146)
Primary pointer page: 230, Index root page: 231
Data pages: 2579, data page slots: 2579, average fill: 73%
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 1505
80 - 99% = 1073

Index FK_DOKUMENT1_REFERENCE_SUTARTYS (6)
Depth: 2, leaf buckets: 457, nodes: 170169
Average data length: 0.00, total dup: 170168, max dup: 170168
Fill distribution:
0 - 19% = 2
20 - 39% = 0
40 - 59% = 414
60 - 79% = 0
80 - 99% = 41

Index FK_DOKUMENT_MATATSAKAGENTAI (2)
Depth: 2, leaf buckets: 457, nodes: 170169
Average data length: 0.00, total dup: 170168, max dup: 170168
Fill distribution:
0 - 19% = 2
20 - 39% = 0
40 - 59% = 414
60 - 79% = 0
80 - 99% = 41

Index FK_DOKUMENT_REFERENCE_BUHSASKA (1)
Depth: 2, leaf buckets: 457, nodes: 170169
Average data length: 0.00, total dup: 170168, max dup: 170168
Fill distribution:
0 - 19% = 2
20 - 39% = 0
40 - 59% = 414
60 - 79% = 0
80 - 99% = 41

Index FK_DOKUMENT_REFERENCE_DOKUMENT (7)
Depth: 2, leaf buckets: 452, nodes: 170169
Average data length: 0.00, total dup: 170162, max dup: 42536
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 405
60 - 79% = 3
80 - 99% = 44

Index FK_DOKUMENT_REFERENCE_OBJEKTAI (3)
Depth: 2, leaf buckets: 457, nodes: 170169
Average data length: 0.00, total dup: 170168, max dup: 170168
Fill distribution:
0 - 19% = 2
20 - 39% = 0
40 - 59% = 414
60 - 79% = 0
80 - 99% = 41

Index FK_DOKUMENT_REFERENCE_PADALINI (4)
Depth: 2, leaf buckets: 459, nodes: 170169
Average data length: 0.00, total dup: 170136, max dup: 43823
Fill distribution:
0 - 19% = 2
20 - 39% = 1
40 - 59% = 409
60 - 79% = 8
80 - 99% = 39

Index FK_DOKUMENT_REFERENCE_PREKINES (8)
Depth: 2, leaf buckets: 457, nodes: 170169
Average data length: 0.00, total dup: 170168, max dup: 170168
Fill distribution:
0 - 19% = 2
20 - 39% = 0
40 - 59% = 414
60 - 79% = 0
80 - 99% = 41

Index FK_DOKUMENT_REFERENCE_PROJEKTA (5)
Depth: 2, leaf buckets: 457, nodes: 170169
Average data length: 0.00, total dup: 170168, max dup: 170168
Fill distribution:
0 - 19% = 2
20 - 39% = 0
40 - 59% = 414
60 - 79% = 0
80 - 99% = 41

Index PK_DOKUMENTUDETALIZACIJOS (0)
Depth: 2, leaf buckets: 412, nodes: 170169
Average data length: 1.00, total dup: 0, max dup: 0
Fill distribution:
0 - 19% = 0
20 - 39% = 1
40 - 59% = 229
60 - 79% = 0
80 - 99% = 182

=============================================

ILGALAIKISTURTAS (164)
Primary pointer page: 266, Index root page: 267
Data pages: 2431, data page slots: 2431, average fill: 74%
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 204
60 - 79% = 1216
80 - 99% = 1011

Index FK_ILGALAIK_REFERENCE_DOKUMENT (6)
Depth: 2, leaf buckets: 412, nodes: 170169
Average data length: 1.00, total dup: 0, max dup: 0
Fill distribution:
0 - 19% = 0
20 - 39% = 1
40 - 59% = 229
60 - 79% = 0
80 - 99% = 182

Index FK_ILGALAIK_REFERENCE_INVENTOR (5)
Depth: 2, leaf buckets: 364, nodes: 170169
Average data length: 0.00, total dup: 155969, max dup: 11
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 45
60 - 79% = 317
80 - 99% = 2

Index FK_ILGALAIK_REFERENCE_ITJUDEJI (7)
Depth: 2, leaf buckets: 458, nodes: 170169
Average data length: 0.00, total dup: 155968, max dup: 155968
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 411
60 - 79% = 2
80 - 99% = 45

Index FK_ILGALAIK_REFERENCE_ITNUSIDE (4)
Depth: 3, leaf buckets: 546, nodes: 170169
Average data length: 0.00, total dup: 14199, max dup: 14199
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 500
60 - 79% = 2
80 - 99% = 44

Index INDEX_100 (2)
Depth: 2, leaf buckets: 458, nodes: 170169
Average data length: 0.00, total dup: 155968, max dup: 155968
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 411
60 - 79% = 2
80 - 99% = 45

Index INDEX_101 (3)
Depth: 3, leaf buckets: 546, nodes: 170169
Average data length: 0.00, total dup: 14199, max dup: 14199
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 500
60 - 79% = 2
80 - 99% = 44

Index INDEX_99 (1)
Depth: 2, leaf buckets: 364, nodes: 170169
Average data length: 0.00, total dup: 155969, max dup: 11
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 45
60 - 79% = 317
80 - 99% = 2

Index PK_ILGALAIKISTURTAS (0)
Depth: 2, leaf buckets: 412, nodes: 170169
Average data length: 1.00, total dup: 0, max dup: 0
Fill distribution:
0 - 19% = 0
20 - 39% = 1
40 - 59% = 229
60 - 79% = 0
80 - 99% = 182

=================================================

ITJUDEJIMAI (158)
Primary pointer page: 254, Index root page: 255
Data pages: 558, data page slots: 558, average fill: 84%
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 1
60 - 79% = 0
80 - 99% = 557

Index FK_ITJUDEJI_NURASYMO_PRIEZAST (11)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14199, max dup: 14199
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_PIRKIM_PRIEZAST (10)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14199, max dup: 14199
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_REFERENCE_AKTAI (15)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14199, max dup: 14199
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_REFERENCE_FINANSAV (9)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14190, max dup: 6525
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_REFERENCE_ITKLASES (13)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14199, max dup: 14199
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_REFERENCE_ITPAVADI (14)
Depth: 2, leaf buckets: 24, nodes: 14200
Average data length: 0.00, total dup: 4057, max dup: 99
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 1
60 - 79% = 0
80 - 99% = 23

Index FK_ITJUDEJI_REFERENCE_ITSIFRAI (12)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 13930, max dup: 2740
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_REFERENCE_ITTURTOG (7)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14198, max dup: 13727
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_REFERENCE_KLAS1 (2)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14199, max dup: 14199
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_REFERENCE_KLAS2 (3)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14199, max dup: 14199
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_REFERENCE_KLAS3 (4)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14199, max dup: 14199
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_REFERENCE_KLAS4 (5)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14199, max dup: 14199
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_REFERENCE_KLAS5 (6)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14199, max dup: 14199
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_REFERENCE_MIESTAI (1)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14193, max dup: 12861
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index FK_ITJUDEJI_REFERENCE_PRIKLAUS (8)
Depth: 2, leaf buckets: 22, nodes: 14200
Average data length: 0.00, total dup: 14196, max dup: 9006
Fill distribution:
0 - 19% = 1
20 - 39% = 0
40 - 59% = 0
60 - 79% = 0
80 - 99% = 21

Index PK_ITJUDEJIMAI (0)
Depth: 2, leaf buckets: 25, nodes: 14200
Average data length: 1.00, total dup: 0, max dup: 0
Fill distribution:
0 - 19% = 0
20 - 39% = 0
40 - 59% = 0
60 - 79% = 1
80 - 99% = 24

========================================================

create table DokumentuDetalizacijos (
DokumentoDetalizacijosID TId not null,
GrieztoTipoKodas SMALLINT not null,
DokumentoAntrastesId TId not null,
PrekinesDetalizacijosID TId,
PadalinioID TId,
ProjektoID TId,
ObjektoID TId,
SutartiesID TId,
MaterialiaiAtsAgentoID TId,
BuhSaskaitosID TId,
constraint PK_DOKUMENTUDETALIZACIJOS primary key
(DokumentoDetalizacijosID)
);

create table ITJudejimai (
ITJudejimoID TId not null,
SifroID TId,
ITKlasesID TId not null,
PagaminimoMetai SMALLINT,
PajamavimoData TData,
EksplotacijosPradzia TData,
SkaiciavimoMetodas SMALLINT,
OrganizacijosAmortizacijosNorma TKiekis not null,
MokestineAmortizacijosNorma TKiekis,
LaisvaAmortizacijosNorma TKiekis,
PradineVerte TPinigai not null,
PradinesVertesPokytis TPinigai not null,
PradinisNusidevejimas TPinigai not null,
PradinioNusidevejimoPokytis TPinigai not null,
LikvidacineVerte TPinigai not null,
LikvidacinesVertesPokytis TPinigai not null,
LikvidavimoProcentas TPinigai not null,
ITPavadinimuID TId not null,
AktoId TId,
MiestoID TId,
KlasesID1 TId,
KlasesID2 TId,
KlasesID3 TId,
KlasesID4 TId,
KlasesID5 TId,
ITTurtogrupesID TId,
PriklausomybesID TId,
FinansavimosaltinioID TId,
PirkimoPriezastiesID TId,
NurasymoPriezastiesID TId,
Adresas TIlgasTekstas,
InventorizacijosData TData,
InventorizacijosNumeris TKodas,
PaskutinioNaudojimoData TData,
Stovis SMALLINT not null,
LikvidavimoData TData,
Rida TKiekis not null,
PradineRida TKiekis not null,
Remontas TKiekis not null,
PradinisRemontas TKiekis not null,
MenesineRida TKiekis not null,
PradinisNusidevejimasLaisvas TPinigai not null,
PradinisNusidevejimasMokest TPinigai not null,
constraint PK_ITJUDEJIMAI primary key (ITJudejimoID)
);

create table IlgalaikisTurtas (
DokumentoDetalizacijosID TId not null,
ITJudejimoID TId,
InventorinioNrID TId not null,
ITNusidevejimoID TId,
constraint PK_ILGALAIKISTURTAS primary key (DokumentoDetalizacijosID)
);

create asc index Index_99 on IlgalaikisTurtas (
InventorinioNrID
);

create asc index Index_100 on IlgalaikisTurtas (
ITJudejimoID
);

create asc index Index_101 on IlgalaikisTurtas (
ITNusidevejimoID
);

alter table DokumentuDetalizacijos
add constraint FK_DOKUMENT_REFERENCE_BUHSASKA foreign key
(BuhSaskaitosID)
references BuhSaskaitos (BuhSaskaitosID);

alter table DokumentuDetalizacijos
add constraint FK_DOKUMENT_MatAtsakAGENTAI foreign key
(MaterialiaiAtsAgentoID)
references Agentai (AgentoID);

alter table DokumentuDetalizacijos
add constraint FK_DOKUMENT_REFERENCE_OBJEKTAI foreign key (ObjektoID)
references Objektai (ObjektoID);

alter table DokumentuDetalizacijos
add constraint FK_DOKUMENT_REFERENCE_PADALINI foreign key (PadalinioID)
references Padaliniai (PadalinioID);

alter table DokumentuDetalizacijos
add constraint FK_DOKUMENT_REFERENCE_PROJEKTA foreign key (ProjektoID)
references Projektai (ProjektoID);

alter table DokumentuDetalizacijos
add constraint FK_DOKUMENT1_REFERENCE_SUTARTYS foreign key
(SutartiesID)
references SutarciuDokAntr (DokumentoAntrastesId);

alter table DokumentuDetalizacijos
add constraint FK_DOKUMENT_REFERENCE_DOKUMENT foreign key
(DokumentoAntrastesId)
references DokumentuAntrastes (DokumentoAntrastesId);

alter table DokumentuDetalizacijos
add constraint FK_DOKUMENT_REFERENCE_PREKINES foreign key
(PrekinesDetalizacijosID)
references PrekinesDetalizacijos (PrekinesDetalizacijosID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_MIESTAI foreign key (MiestoID)
references Miestai (MiestoID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_KLAS1 foreign key (KlasesID1)
references Klases (KlasesID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_KLAS2 foreign key (KlasesID2)
references Klases (KlasesID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_KLAS3 foreign key (KlasesID3)
references Klases (KlasesID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_KLAS4 foreign key (KlasesID4)
references Klases (KlasesID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_KLAS5 foreign key (KlasesID5)
references Klases (KlasesID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_ITTURTOG foreign key
(ITTurtogrupesID)
references ITTurtoGrupe (ITTurtogrupesID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_PRIKLAUS foreign key
(PriklausomybesID)
references Priklausomybe (PriklausomybesID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_FINANSAV foreign key
(FinansavimosaltinioID)
references Finansavimosaltinis (FinansavimosaltinioID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_PIRKIM_PRIEZAST foreign key
(PirkimoPriezastiesID)
references Priezastys (PriezastiesID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_NURASYMO_PRIEZAST foreign key
(NurasymoPriezastiesID)
references Priezastys (PriezastiesID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_ITSIFRAI foreign key (SifroID)
references ITSifrai (SifroID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_ITKLASES foreign key (ITKlasesID)
references ITKlases (ITKlasesID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_ITPAVADI foreign key
(ITPavadinimuID)
references ITPavadinimai (ITPavadinimuID);

alter table ITJudejimai
add constraint FK_ITJUDEJI_REFERENCE_AKTAI foreign key (AktoId)
references Aktai (AktoId);

alter table IlgalaikisTurtas
add constraint FK_ILGALAIK_REFERENCE_ITNUSIDE foreign key
(ITNusidevejimoID)
references ITNusidevejimas (ITNusidevejimoID);

alter table IlgalaikisTurtas
add constraint FK_ILGALAIK_REFERENCE_INVENTOR foreign key
(InventorinioNrID)
references InventoriniaiNr (InventorinioNrID);

alter table IlgalaikisTurtas
add constraint FK_ILGALAIK_REFERENCE_DOKUMENT foreign key
(DokumentoDetalizacijosID)
references DokumentuDetalizacijos (DokumentoDetalizacijosID);

alter table IlgalaikisTurtas
add constraint FK_ILGALAIK_REFERENCE_ITJUDEJI foreign key
(ITJudejimoID)
references ITJudejimai (ITJudejimoID);