The below Query is taking 15 to 20 Sec which is not expected. Please help in refactoring this query
SELECT upin.bipuserid userid,
upin.orgn_entity_id entityId,
COUNT(upin.ORGN_ENTITY_ID)
over (partition BY upin.bipuserid) as numentities,
COUNT(DISTINCT(SUBSTR(upin.ORGN_ENTITY_ID,6,2)))
over (partition BY upin.bipuserid) as numentitytypes
FROM userpermission upin;
There are 1614246 Records in the table. Index has been created on both columns.
Below is the table structure
Column Name Data Type
BIPUSERID VARCHAR2 (20 Char)
ROLECODE VARCHAR2 (25 Char)
ORGN_ENTITY_ID VARCHAR2 (10 Char)
ACT_CD VARCHAR2 (1 Char)