Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Долгий одиночный insert (online_analyze) #113

Open
Assignees
funbringer
@sgrinko

Description

@sgrinko

Работаю на следующих версиях:

select get_pathman_lib_version()10402select pgpro_version()pgpro_versionPostgresPro9.6.3.3on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu5.4.0-6ubuntu1~16.04.4)5.4.020160609,64-bit

использую RANGE секционирование 1 месяц. Выполняю такой код:
на таблице base.fact_events сейчас 68 секций
структура таблицы

CREATETABLEbase.fact_events(  idbigserialNOT NULL,  rgu_service_idinteger,  rgu_authority_idinteger,  statusinteger,  review_statusinteger,  created_attimestamp without time zoneNOT NULL DEFAULT now(),  updated_attimestamp without time zoneNOT NULL,  deleted_attimestamp without time zone,  event_datedate,  tokencharacter varying(50),  mobilecharacter varying(25),  emailcharacter varying(128),CONSTRAINT fact_events_pkeyPRIMARY KEY (id));CREATEINDEXindex_fact_events_on_created_atONbase.fact_events  USING btree  (created_at);...другие индексы

индекс по полю created_at есть на таблицах наследования

CREATETABLEbase.fact_events_11(-- Inherited from table base.fact_events:  id bigint NOT NULL DEFAULT nextval('base.fact_events_id_seq'::regclass),-- Inherited from table base.fact_events:  rgu_service_id integer,-- Inherited from table base.fact_events:  rgu_authority_id integer,-- Inherited from table base.fact_events:  status integer,-- Inherited from table base.fact_events:  review_status integer,-- Inherited from table base.fact_events:  created_at timestamp without time zone NOT NULL DEFAULT now(),-- Inherited from table base.fact_events:  updated_at timestamp without time zone NOT NULL,-- Inherited from table base.fact_events:  deleted_at timestamp without time zone,-- Inherited from table base.fact_events:  event_date date,-- Inherited from table base.fact_events:  token character varying(50),-- Inherited from table base.fact_events:  mobile character varying(25),-- Inherited from table base.fact_events:  email character varying(128),CONSTRAINT fact_events_11_pkeyPRIMARY KEY (id)CONSTRAINT pathman_fact_events_11_checkCHECK (created_at>='2012-11-01 00:00:00'::timestamp without time zoneAND created_at<'2012-12-01 00:00:00'::timestamp without time zone))INHERITS (base.fact_events)WITH (  OIDS=FALSE);CREATEINDEXfact_events_11_created_at_idxONbase.fact_events_11  USING btree  (created_at);...другие индексы

данные в конфиге

select*frompublic.pathman_configpartrelbase.fact_eventsexpr        created_atparttype2range_interval1 moncooked_expr{VAR :varno1 :varattno6 :vartype1114 :vartypmod-1 :varcollid0 :varlevelsup0 :varnoold1 :varoattno6 :location8}select*frompublic.pathman_config_paramspartrel               enable_parent   auto   init_callback     spawn_using_bgwbase.fact_events       t                  t<NULL>               f

до этого пакетно в таблицу вставилось

selectcount(*)frombase.fact_eventscount22801606

и потом конкуретно выполнено партиционирование.
после этого был выполнен VACUUM FULL FREEZE ANALYZE base.fact_events;
главная таблицы после этого имеет размер 48кб и 0 строк. Все данные распределены по секциям.

выполняю вставку 1 строки
сначала смотрим план:

explain(COSTS, BUFFERS, TIMING, ANALYZE, VERBOSE)INSERT INTObase.fact_events (rgu_service_id, rgu_authority_id, created_at, updated_at)VALUES (165708,91643,'2017-08-14 08:52:23.798822','2017-08-14 08:52:23.798822') RETURNING id;QUERY PLANInsertonbase.fact_events  (cost=0.00..0.01 rows=1 width=148) (actualtime=1.313..1.314 rows=1 loops=1)  Output: id  Buffers: shared hit=22 dirtied=9->  Custom Scan (PartitionFilter)  (cost=0.00..0.01 rows=1 width=148) (actualtime=0.051..0.051 rows=1 loops=1)        Output: (nextval('base.fact_events_id_seq'::regclass)), (165708), (91643), (NULL::integer), (NULL::integer), ('2017-08-14 08:52:23.798822'::timestamp without time zone), ('2017-08-14 08:52:23.798822'::timestamp without time zone), (NULL::timestamp without time zone), (NULL::date), (NULL::character varying), (NULL::character varying), (NULL::character varying)        Buffers: shared hit=2 dirtied=1->  Result  (cost=0.00..0.01 rows=1 width=148) (actualtime=0.024..0.024 rows=1 loops=1)              Output: nextval('base.fact_events_id_seq'::regclass),165708,91643,NULL::integer,NULL::integer,'2017-08-14 08:52:23.798822'::timestamp without time zone,'2017-08-14 08:52:23.798822'::timestamp without time zone,NULL::timestamp without time zone,NULL::date,NULL::character varying,NULL::character varying,NULL::character varying              Buffers: shared hit=2 dirtied=1Planningtime:0.042 msTrigger RI_ConstraintTrigger_c_193188 forconstraint fact_events_68_rgu_service_id_fkeyon fact_events_68:time=0.323 calls=1Trigger RI_ConstraintTrigger_c_193193 forconstraint fact_events_68_rgu_authority_id_fkeyon fact_events_68:time=0.270 calls=1Executiontime:886.790 ms

теперь выполняем код в транзакции

begin;INSERT INTObase.fact_events (rgu_service_id, rgu_authority_id, created_at, updated_at)VALUES (165708,91643,'2017-08-14 08:52:23.798822','2017-08-14 08:52:23.798822') RETURNING id;rollback;

результат:

INFO:  analyzing"base.fact_events"INFO:"fact_events": scanned0 of0 pages, containing0 live rowsand0 dead rows;0 rowsin sample,0 estimated total rowsINFO:  analyzing"base.fact_events" inheritance treeINFO:"fact_events_11": scanned1 of2 pages, containing97 live rowsand0 dead rows;1 rowsin sample,166 estimated total rowsINFO:"fact_events_12": scanned1 of2 pages, containing97 live rowsand0 dead rows;1 rowsin sample,183 estimated total rowsINFO:"fact_events_16": scanned579 of1161 pages, containing45154 live rowsand0 dead rows;579 rowsin sample,90592 estimated total rowsINFO:"fact_events_17": scanned998 of2002 pages, containing77850 live rowsand0 dead rows;998 rowsin sample,156178 estimated total rowsINFO:"fact_events_18": scanned458 of918 pages, containing35875 live rowsand0 dead rows;458 rowsin sample,71894 estimated total rowsINFO:"fact_events_19": scanned786 of1576 pages, containing61423 live rowsand0 dead rows;786 rowsin sample,123166 estimated total rowsINFO:"fact_events_20": scanned719 of1442 pages, containing56102 live rowsand0 dead rows;719 rowsin sample,112527 estimated total rowsINFO:"fact_events_21": scanned865 of1735 pages, containing67537 live rowsand0 dead rows;865 rowsin sample,135495 estimated total rowsINFO:"fact_events_22": scanned815 of1636 pages, containing63498 live rowsand0 dead rows;815 rowsin sample,127520 estimated total rowsINFO:"fact_events_23": scanned824 of1654 pages, containing64561 live rowsand0 dead rows;824 rowsin sample,129672 estimated total rowsINFO:"fact_events_24": scanned459 of921 pages, containing35820 live rowsand0 dead rows;459 rowsin sample,71905 estimated total rowsINFO:"fact_events_25": scanned487 of978 pages, containing38024 live rowsand0 dead rows;487 rowsin sample,76353 estimated total rowsINFO:"fact_events_26": scanned750 of1505 pages, containing58605 live rowsand0 dead rows;750 rowsin sample,117600 estimated total rowsINFO:"fact_events_27": scanned590 of1183 pages, containing46119 live rowsand0 dead rows;590 rowsin sample,92462 estimated total rowsINFO:"fact_events_28": scanned555 of1113 pages, containing43373 live rowsand0 dead rows;555 rowsin sample,87041 estimated total rowsINFO:"fact_events_29": scanned3000 of6019 pages, containing284326 live rowsand0 dead rows;3000 rowsin sample,570828 estimated total rowsINFO:"fact_events_30": scanned1980 of3973 pages, containing187429 live rowsand0 dead rows;1980 rowsin sample,376179 estimated total rowsINFO:"fact_events_31": scanned2399 of4813 pages, containing227117 live rowsand0 dead rows;2399 rowsin sample,455462 estimated total rowsINFO:"fact_events_32": scanned2586 of5187 pages, containing239678 live rowsand0 dead rows;2586 rowsin sample,480657 estimated total rowsINFO:"fact_events_33": scanned3179 of6377 pages, containing299436 live rowsand0 dead rows;3179 rowsin sample,600662 estimated total rowsINFO:"fact_events_34": scanned2642 of5301 pages, containing254842 live rowsand0 dead rows;2642 rowsin sample,511321 estimated total rowsINFO:"fact_events_35": scanned3216 of6452 pages, containing310877 live rowsand0 dead rows;3216 rowsin sample,623762 estimated total rowsINFO:"fact_events_36": scanned4207 of8440 pages, containing399773 live rowsand0 dead rows;4207 rowsin sample,802087 estimated total rowsINFO:"fact_events_37": scanned1908 of3827 pages, containing183399 live rowsand0 dead rows;1908 rowsin sample,367822 estimated total rowsINFO:"fact_events_38": scanned2138 of4290 pages, containing205421 live rowsand0 dead rows;2138 rowsin sample,412173 estimated total rowsINFO:"fact_events_39": scanned2786 of5589 pages, containing266143 live rowsand0 dead rows;2786 rowsin sample,534013 estimated total rowsINFO:"fact_events_40": scanned2786 of5589 pages, containing264590 live rowsand0 dead rows;2786 rowsin sample,531007 estimated total rowsINFO:"fact_events_41": scanned2769 of5555 pages, containing262066 live rowsand0 dead rows;2769 rowsin sample,525909 estimated total rowsINFO:"fact_events_42": scanned2615 of5247 pages, containing248462 live rowsand0 dead rows;2615 rowsin sample,498418 estimated total rowsINFO:"fact_events_43": scanned1183 of2374 pages, containing113432 live rowsand0 dead rows;1183 rowsin sample,227606 estimated total rowsINFO:"fact_events_44": scanned434 of871 pages, containing42072 live rowsand0 dead rows;434 rowsin sample,84404 estimated total rowsINFO:"fact_events_45": scanned539 of1081 pages, containing51964 live rowsand0 dead rows;539 rowsin sample,104190 estimated total rowsINFO:"fact_events_46": scanned1108 of2223 pages, containing102339 live rowsand0 dead rows;1108 rowsin sample,205433 estimated total rowsINFO:"fact_events_47": scanned1213 of2434 pages, containing113776 live rowsand0 dead rows;1213 rowsin sample,228022 estimated total rowsINFO:"fact_events_48": scanned1297 of2603 pages, containing121951 live rowsand0 dead rows;1297 rowsin sample,244601 estimated total rowsINFO:"fact_events_49": scanned1233 of2474 pages, containing113970 live rowsand0 dead rows;1233 rowsin sample,228811 estimated total rowsINFO:"fact_events_50": scanned1609 of3228 pages, containing155339 live rowsand0 dead rows;1609 rowsin sample,311778 estimated total rowsINFO:"fact_events_51": scanned3711 of7445 pages, containing359550 live rowsand0 dead rows;3711 rowsin sample,721346 estimated total rowsINFO:"fact_events_52": scanned5686 of11407 pages, containing551053 live rowsand0 dead rows;5686 rowsin sample,1105516 estimated total rowsINFO:"fact_events_53": scanned3921 of7866 pages, containing379556 live rowsand0 dead rows;3921 rowsin sample,761444 estimated total rowsINFO:"fact_events_54": scanned4266 of8559 pages, containing413235 live rowsand0 dead rows;4266 rowsin sample,829050 estimated total rowsINFO:"fact_events_55": scanned4237 of8500 pages, containing410090 live rowsand0 dead rows;4237 rowsin sample,822742 estimated total rowsINFO:"fact_events_56": scanned4667 of9362 pages, containing451870 live rowsand0 dead rows;4667 rowsin sample,906483 estimated total rowsINFO:"fact_events_57": scanned3906 of7836 pages, containing378153 live rowsand0 dead rows;3906 rowsin sample,758625 estimated total rowsINFO:"fact_events_58": scanned4176 of8377 pages, containing404405 live rowsand0 dead rows;4176 rowsin sample,811217 estimated total rowsINFO:"fact_events_59": scanned4077 of8180 pages, containing394670 live rowsand0 dead rows;4077 rowsin sample,791919 estimated total rowsINFO:"fact_events_60": scanned5207 of10447 pages, containing504102 live rowsand0 dead rows;5207 rowsin sample,1011430 estimated total rowsINFO:"fact_events_61": scanned3090 of6200 pages, containing299062 live rowsand0 dead rows;3090 rowsin sample,600125 estimated total rowsINFO:"fact_events_62": scanned2929 of5876 pages, containing283054 live rowsand0 dead rows;2929 rowsin sample,567871 estimated total rowsINFO:"fact_events_63": scanned3385 of6790 pages, containing327382 live rowsand0 dead rows;3385 rowsin sample,656647 estimated total rowsINFO:"fact_events_64": scanned3478 of6977 pages, containing336402 live rowsand0 dead rows;3478 rowsin sample,674748 estimated total rowsINFO:"fact_events_65": scanned2176 of4366 pages, containing210441 live rowsand0 dead rows;2176 rowsin sample,422277 estimated total rowsINFO:"fact_events_66": scanned2789 of5595 pages, containing269767 live rowsand0 dead rows;2789 rowsin sample,541143 estimated total rowsINFO:"fact_events_67": scanned2298 of4610 pages, containing222094 live rowsand0 dead rows;2298 rowsin sample,445542 estimated total rowsINFO:"fact_events_68": scanned282 of566 pages, containing27277 live rowsand1 dead rows;282 rowsin sample,54694 estimated total rowsINFO:  analyze"fact_events" took1.55 secondsTotal query runtime:1.5 secs1 row retrieved.

1.5 секунды + идут сканирования всех секций... что я делаю не так?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp