Ну и удачи в поисках. Текстом я бы мог попробовать у себя, а так — нет.
Индексы: "core_zreportcurrencypart_pkey" PRIMARY KEY, btree (id) "core_zreportcurrencypart_currency_byn_idx" btree ((currency::text = 'BYN'::text)) "core_zreportcurrencypart_currency_idx" btree (currency) "core_zreportcurrencypart_currency_not_byn_idx" btree ((currency::text <> 'BYN'::text)) INVALID "core_zreportcurrencypart_empty_byn_idx" btree ((amount_in_byn IS NULL), (currency::text <> 'BYN'::text)) INVALID "core_zreportcurrencypart_zreport_id" btree (zreport_id) Ограничения-проверки: "core_zreportcurrencypart_cancels_count_check" CHECK (cancels_count >= 0) "core_zreportcurrencypart_corrections_count_check" CHECK (corrections_count >= 0) "core_zreportcurrencypart_documents_count_check" CHECK (documents_count >= 0) "core_zreportcurrencypart_issuances_count_check" CHECK (issuances_count >= 0) "core_zreportcurrencypart_placing_count_check" CHECK (placing_count >= 0) "core_zreportcurrencypart_refunds_count_check" CHECK (refunds_count >= 0) "core_zreportcurrencypart_unregistred_cancels_count_check" CHECK (unregistred_cancels_count >= 0) Ограничения внешнего ключа: "core_zreportcurr_zreport_id_2d29e4ac9e4942e7_fk_core_zreport_id" FOREIGN KEY (zreport_id) REFERENCES core_zreport(id) DEFERRABLE INITIALLY DEFERRED
CREATE TABLE public.core_zreportcurrencypart ( id serial NOT NULL, zreport_id int4 NOT NULL, currency varchar(3) NOT NULL, documents_count int4 NOT NULL, amount numeric(100,2) NOT NULL, clearing_amount numeric(100,2) NOT NULL, cash_amount numeric(100,2) NOT NULL, refunds_count int2 NOT NULL, refunds_amount numeric(100,2) NOT NULL, placing_count int2 NOT NULL, placing_amount numeric(100,2) NOT NULL, issuances_count int2 NOT NULL, issuances_amount numeric(100,2) NOT NULL, unregistred_cancels_count int2 NOT NULL, unregistred_cancels_amount numeric(100,2) NOT NULL, cancels_count int2 NOT NULL, cancels_amount numeric(100,2) NOT NULL, corrections_count int2 NOT NULL, corrections_amount numeric(100,2) NOT NULL, amount_in_byn numeric(100,2) NULL, clearing_amount_in_byn numeric(100,2) NULL, cash_amount_in_byn numeric(100,2) NULL, refunds_amount_in_byn numeric(100,2) NULL, placing_amount_in_byn numeric(100,2) NULL, issuances_amount_in_byn numeric(100,2) NULL, unregistred_cancels_amount_in_byn numeric(100,2) NULL, cancels_amount_in_byn numeric(100,2) NULL, corrections_amount_in_byn numeric(100,2) NULL, CONSTRAINT core_zreportcurrencypart_cancels_count_check CHECK ((cancels_count >= 0)), CONSTRAINT core_zreportcurrencypart_corrections_count_check CHECK ((corrections_count >= 0)), CONSTRAINT core_zreportcurrencypart_documents_count_check CHECK ((documents_count >= 0)), CONSTRAINT core_zreportcurrencypart_issuances_count_check CHECK ((issuances_count >= 0)), CONSTRAINT core_zreportcurrencypart_pkey PRIMARY KEY (id), CONSTRAINT core_zreportcurrencypart_placing_count_check CHECK ((placing_count >= 0)), CONSTRAINT core_zreportcurrencypart_refunds_count_check CHECK ((refunds_count >= 0)), CONSTRAINT core_zreportcurrencypart_unregistred_cancels_count_check CHECK ((unregistred_cancels_count >= 0)), CONSTRAINT core_zreportcurr_zreport_id_2d29e4ac9e4942e7_fk_core_zreport_id FOREIGN KEY (zreport_id) REFERENCES core_zreport(id) DEFERRABLE INITIALLY DEFERRED ); CREATE INDEX core_zreportcurrencypart_currency_byn_idx ON public.core_zreportcurrencypart USING btree ((((currency)::text = 'BYN'::text))); CREATE INDEX core_zreportcurrencypart_currency_idx ON public.core_zreportcurrencypart USING btree (currency); CREATE INDEX core_zreportcurrencypart_currency_not_byn_idx ON public.core_zreportcurrencypart USING btree ((((currency)::text <> 'BYN'::text))); CREATE INDEX core_zreportcurrencypart_empty_byn_idx ON public.core_zreportcurrencypart USING btree (((amount_in_byn IS NULL)), (((currency)::text <> 'BYN'::text))); CREATE INDEX core_zreportcurrencypart_zreport_id ON public.core_zreportcurrencypart USING btree (zreport_id);
Ну и вот проблема, во-первых: "core_zreportcurrencypart_currency_not_byn_idx" btree ((currency::text <> 'BYN'::text)) INVALID "core_zreportcurrencypart_empty_byn_idx" btree ((amount_in_byn IS NULL), (currency::text <> 'BYN'::text)) INVALID Индексы-то не создались.
дада. вот увидел только тут бобер то не показывает
Вот в том числе поэтому я не люблю все эти GUI — они "соврут" подобным образом, и N часов потеряно. ;( А индекс-то рабочий — https://dbfiddle.uk/?rdbms=postgres_13&fiddle=1771471693009c78b749b3a5458708bc
да. помогло. enable_seqscan=off Bitmap Heap Scan on core_zreportcurrencypart (cost=395223.93..3452834.69 rows=12730598 width=478) (actual time=1414.375..167771.064 rows=12711361 loops=1) Filter: ((amount_in_byn IS NULL) AND ((currency)::text <> 'BYN'::text)) Rows Removed by Filter: 43227793 Heap Blocks: exact=21977 lossy=710500 -> Bitmap Index Scan on core_zreportcurrencypart_empty_byn_idx (cost=0.00..392041.28 rows=30119721 width=0) (actual time=1406.828..1406.828 rows=12711383 loops=1) Index Cond: (((amount_in_byn IS NULL) = true) AND (((currency)::text <> 'BYN'::text) = true)) Planning Time: 0.829 ms Execution Time: 168651.479 ms enable_seqscan=on; Seq Scan on core_zreportcurrencypart (cost=0.00..3069488.28 rows=12730770 width=478) (actual time=0.041..340608.998 rows=12711465 loops=1) Filter: ((amount_in_byn IS NULL) AND ((currency)::text <> 'BYN'::text)) Rows Removed by Filter: 107764263 Planning Time: 0.185 ms Execution Time: 341461.589 ms чувствительно да сейчас еще вакум с анализом прогоню
Т.е. вопрос оценок, всё же. Насколько они (настройки PROD сервера postgres) соответствуют действительности — Вам виднее.
Обсуждают сегодня