A
Size: a a a
A
A
s
Gather (cost=1000.57..708213.47 rows=599273 width=34) (actual time=0.598..2202.731 rows=656324 loops=1)
Workers Planned: 4
Workers Launched: 4
Buffers: shared hit=3296018 read=262261
-> Nested Loop (cost=0.56..647286.17 rows=149818 width=34) (actual time=0.127..2101.260 rows=131265 loops=5)
Buffers: shared hit=3296018 read=262261
-> Parallel Seq Scan on "AO_8542F1_IFJ_OBJ_ATTR" oa (cost=0.00..423521.28 rows=150508 width=8) (actual time=0.070..1007.676 rows=131265 loops=5)
Filter: ("OBJECT_TYPE_ATTRIBUTE_ID" = ANY ('{529,10,506,143}'::integer[]))
Rows Removed by Filter: 7891993
Buffers: shared hit=10822 read=262261
-> Index Scan using index_ao_8542f1_ifj228666017 on "AO_8542F1_IFJ_OBJ_ATTR_VAL" oav (cost=0.56..1.48 rows=1 width=42) (actual time=0.008..0.008 rows=1 loops=656324)
Index Cond: ("OBJECT_ATTRIBUTE_ID" = oa."ID")
Buffers: shared hit=3285196
Planning time: 0.431 ms
Execution time: 2225.289 ms
(15 rows)
Table "public.AO_8542F1_IFJ_OBJ_ATTR"
Column | Type | Modifiers
--------------------------+---------+-----------------------------------------------------------------------
ID | bigint | not null default nextval('"AO_8542F1_IFJ_OBJ_ATTR_ID_seq"'::regclass)
OBJECT_ID | integer |
OBJECT_TYPE_ATTRIBUTE_ID | integer |
UPDATED | bigint |
Indexes:
"AO_8542F1_IFJ_OBJ_ATTR_pkey" PRIMARY KEY, btree ("ID")
"index_ao_8542f1_ifj268009346" btree ("OBJECT_TYPE_ATTRIBUTE_ID")
"index_ao_8542f1_ifj43488772" btree ("OBJECT_ID")
"index_ao_insight_2" btree ("ID") WHERE "OBJECT_TYPE_ATTRIBUTE_ID" = ANY (ARRAY[529, 10, 506, 143])
Foreign-key constraints:
"fk_ao_8542f1_ifj_obj_attr_object_id" FOREIGN KEY ("OBJECT_ID") REFERENCES "AO_8542F1_IFJ_OBJ"("ID")
"fk_ao_8542f1_ifj_obj_attr_object_type_attribute_id" FOREIGN KEY ("OBJECT_TYPE_ATTRIBUTE_ID") REFERENCES "AO_8542F1_IFJ_OBJ_TYPE_ATTR"("ID")
Referenced by:
TABLE ""AO_8542F1_IFJ_OBJ_ATTR_VAL"" CONSTRAINT "fk_ao_8542f1_ifj_obj_attr_val_object_attribute_id" FOREIGN KEY ("OBJECT_ATTRIBUTE_ID") REFERENCES "AO_8542F1_IFJ_OBJ_ATTR"("ID")
total used free shared buff/cache available
Mem: 24947 2118 207 5803 22620 16659
Swap: 3071 0 3071
Total: 28019 2118 3279
max_wal_size = 4GB
min_wal_size = 1GB
checkpoint_completion_target = 0.7
effective_io_concurrency = 200 # 1-1000; 0 disables prefetching
max_worker_processes = 8 # (change requires restart)
max_parallel_workers_per_gather = 4
work_mem = 8987kB
maintenance_work_mem = 1408MB
shared_buffers = 6240MB
YS
A
s
A
s
YS
А
L
VY
IK
VY
EF
with max_salary_table as (
SELECT Employee.name,
D.name as name_company,
Employee.salary,
dense_rank() OVER (PARTITION BY Employee.departmentId order by salary DESC) as rating
from Employee
join Department D on D.id = Employee.departmentId
)
select name, name_company, salary
from max_salary_table
where rating = 1;
EF
VY
DISTINCT ON
. но не факт, что это будет самый быстрый результат в любой ситуациEF
А
with max_salary_table as (
SELECT Employee.name,
D.name as name_company,
Employee.salary,
dense_rank() OVER (PARTITION BY Employee.departmentId order by salary DESC) as rating
from Employee
join Department D on D.id = Employee.departmentId
)
select name, name_company, salary
from max_salary_table
where rating = 1;
EF