From 905537f9afde3edd2a08acc85088d959dd8a2b53 Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Sat, 6 Jun 2020 00:08:09 +0530 Subject: [PATCH] Add index to DM_DEVICE_DETAIL table --- .../src/main/resources/dbscripts/cdm/h2.sql | 2 ++ .../src/main/resources/dbscripts/cdm/mssql.sql | 3 +++ .../src/main/resources/dbscripts/cdm/mysql.sql | 2 ++ .../src/main/resources/dbscripts/cdm/oracle.sql | 4 ++++ .../src/main/resources/dbscripts/cdm/postgresql.sql | 4 ++-- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index 3665adbfe39..4d16db5abea 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -502,6 +502,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ON UPDATE NO ACTION ); +CREATE INDEX IDX_DM_DEVICE_DETAIL_DID_EID ON DM_DEVICE_DETAIL(DEVICE_ID, ENROLMENT_ID); + CREATE TABLE IF NOT EXISTS DM_DEVICE_HISTORY_LAST_SEVEN_DAYS ( ID INTEGER AUTO_INCREMENT NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index 31c9e228b58..8739701915a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -581,6 +581,9 @@ CREATE TABLE DM_DEVICE_DETAIL ( ON UPDATE NO ACTION ); +IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_DM_DEVICE_DETAIL_DID_EID' AND OBJECT_ID = OBJECT_ID('DM_DEVICE_DETAIL')) +CREATE INDEX IDX_DM_DEVICE_DETAIL_DID_EID ON DM_DEVICE_DETAIL(DEVICE_ID, ENROLMENT_ID); + IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_TYPE_PLATFORM]') AND TYPE IN (N'U')) CREATE TABLE DM_DEVICE_TYPE_PLATFORM( ID int IDENTITY(1, 1) NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index 8a7d42f7b3a..ba57c267575 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -599,6 +599,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ) ENGINE = InnoDB; +CREATE INDEX IDX_DM_DEVICE_DETAIL_DID_EID ON DM_DEVICE_DETAIL(DEVICE_ID, ENROLMENT_ID); + -- ----------------------------------------------------- -- Table `DM_DEVICE_TYPE_PLATFORM` -- ----------------------------------------------------- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index 41b64110215..3ca15d3f388 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -912,6 +912,10 @@ CREATE TABLE DM_DEVICE_DETAIL ( REFERENCES DM_ENROLMENT (ID) ) / + +CREATE INDEX IDX_DM_DEVICE_DETAIL_DID_EID ON DM_DEVICE_DETAIL(DEVICE_ID, ENROLMENT_ID) +/ + -- Generate ID using sequence and trigger CREATE SEQUENCE DM_DEVICE_DETAIL_seq START WITH 1 INCREMENT BY 1 NOCACHE / diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 08616f9145b..dc3d264cfd9 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -600,11 +600,11 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION -) -; +); CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC); CREATE INDEX FK_DM_ENROLMENT_DEVICE_DETAILS_idx ON DM_DEVICE_DETAIL (ENROLMENT_ID ASC); +CREATE INDEX IDX_DM_DEVICE_DETAIL_DID_EID ON DM_DEVICE_DETAIL(DEVICE_ID, ENROLMENT_ID); -- METADATA TABLE -- CREATE TABLE IF NOT EXISTS DM_METADATA (