diff --git a/security-admin/db/mysql/optimized/current/ranger_core_db_mysql.sql b/security-admin/db/mysql/optimized/current/ranger_core_db_mysql.sql index 73ad546112..1c74a39e7a 100644 --- a/security-admin/db/mysql/optimized/current/ranger_core_db_mysql.sql +++ b/security-admin/db/mysql/optimized/current/ranger_core_db_mysql.sql @@ -447,6 +447,7 @@ CREATE TABLE `x_trx_log_v2` ( PRIMARY KEY (`id`), KEY `x_trx_log_v2_FK_added_by_id` (`added_by_id`), KEY `x_trx_log_v2_cr_time` (`create_time`), + KEY `x_trx_log_v2_action` (`action`), KEY `x_trx_log_v2_trx_id` (`trx_id`) )ROW_FORMAT=DYNAMIC; diff --git a/security-admin/db/mysql/patches/076-create-index-for-x_trx_log_v2.sql b/security-admin/db/mysql/patches/076-create-index-for-x_trx_log_v2.sql new file mode 100644 index 0000000000..bc43aa4a9e --- /dev/null +++ b/security-admin/db/mysql/patches/076-create-index-for-x_trx_log_v2.sql @@ -0,0 +1,28 @@ +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +drop procedure if exists create_index_for_x_trx_log_v2; + +delimiter ;; +create procedure create_index_for_x_trx_log_v2() begin +if exists (SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='x_trx_log_v2') then + if not exists (SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='x_trx_log_v2' AND index_name='x_trx_log_v2_action') then + CREATE INDEX x_trx_log_v2_action ON x_trx_log_v2(action); + end if; +end if; +end;; + +delimiter ; +call create_index_for_x_trx_log_v2(); diff --git a/security-admin/db/oracle/optimized/current/ranger_core_db_oracle.sql b/security-admin/db/oracle/optimized/current/ranger_core_db_oracle.sql index 40f71e28b9..0742c0af32 100644 --- a/security-admin/db/oracle/optimized/current/ranger_core_db_oracle.sql +++ b/security-admin/db/oracle/optimized/current/ranger_core_db_oracle.sql @@ -1731,6 +1731,7 @@ CREATE INDEX x_resource_FK_parent_id ON x_resource (parent_id); CREATE INDEX x_resource_cr_time ON x_resource(create_time); CREATE INDEX x_resource_up_time ON x_resource (update_time); CREATE INDEX x_trx_log_v2_FK_added_by_id ON x_trx_log_v2 (added_by_id); +CREATE INDEX x_trx_log_v2_action ON x_trx_log_v2 (action); CREATE INDEX x_trx_log_v2_cr_time ON x_trx_log_v2 (create_time); CREATE INDEX x_trx_log_v2_trx_id ON x_trx_log_v2 (trx_id); CREATE INDEX x_user_FK_added_by_id ON x_user (added_by_id); diff --git a/security-admin/db/oracle/patches/075-create-index-for-x_trx_log_v2.sql b/security-admin/db/oracle/patches/075-create-index-for-x_trx_log_v2.sql new file mode 100644 index 0000000000..a3c031aed3 --- /dev/null +++ b/security-admin/db/oracle/patches/075-create-index-for-x_trx_log_v2.sql @@ -0,0 +1,29 @@ +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- sync_source_info CLOB NOT NULL, + +DECLARE + v_index_exists number:=0; + v_table_exists number := 0; +BEGIN + SELECT COUNT(*) INTO v_table_exists FROM USER_TABLES WHERE TABLE_NAME = upper('x_trx_log_v2'); + IF (v_table_exists > 0) THEN + SELECT COUNT(*) INTO v_index_exists FROM USER_INDEXES WHERE INDEX_NAME = upper('x_trx_log_v2_action') AND TABLE_NAME= upper('x_trx_log_v2'); + IF (v_index_exists = 0) THEN + execute IMMEDIATE 'CREATE INDEX x_trx_log_v2_action ON x_trx_log_v2(action)'; + commit; + END IF; + END IF; +END;/ diff --git a/security-admin/db/postgres/optimized/current/ranger_core_db_postgres.sql b/security-admin/db/postgres/optimized/current/ranger_core_db_postgres.sql index 980f22f140..c205b4888f 100644 --- a/security-admin/db/postgres/optimized/current/ranger_core_db_postgres.sql +++ b/security-admin/db/postgres/optimized/current/ranger_core_db_postgres.sql @@ -1758,6 +1758,7 @@ CREATE INDEX x_resource_FK_parent_id ON x_resource(parent_id); CREATE INDEX x_resource_cr_time ON x_resource(create_time); CREATE INDEX x_resource_up_time ON x_resource(update_time); CREATE INDEX x_trx_log_v2_FK_added_by_id ON x_trx_log_v2(added_by_id); +CREATE INDEX x_trx_log_v2_action ON x_trx_log_v2(action); CREATE INDEX x_trx_log_v2_cr_time ON x_trx_log_v2(create_time); CREATE INDEX x_trx_log_v2_trx_id ON x_trx_log_v2(trx_id); CREATE INDEX x_user_FK_added_by_id ON x_user(added_by_id); diff --git a/security-admin/db/postgres/patches/076-create-index-for-x_trx_log_v2.sql b/security-admin/db/postgres/patches/076-create-index-for-x_trx_log_v2.sql new file mode 100644 index 0000000000..a5b37acaed --- /dev/null +++ b/security-admin/db/postgres/patches/076-create-index-for-x_trx_log_v2.sql @@ -0,0 +1,37 @@ +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +select 'delimiter start'; +CREATE OR REPLACE FUNCTION create_index_for_x_trx_log_v2() +RETURNS void AS $$ +DECLARE + v_attnum1 integer := 0; + v_table_exists integer := 0; +BEGIN + SELECT COUNT(*) INTO v_table_exists FROM pg_class WHERE relname = 'x_trx_log_v2'; + IF v_table_exists > 0 THEN + select attnum into v_attnum1 from pg_attribute where attrelid in(select oid from pg_class where relname='x_trx_log_v2') and attname in('action'); + IF v_attnum1 > 0 THEN + IF not exists (select * from pg_index where indrelid in(select oid from pg_class where relname='x_trx_log_v2') and indkey[0]=v_attnum1) THEN + CREATE INDEX x_trx_log_v2_action ON x_trx_log_v2(action); + END IF; + END IF; + END IF; +END; +$$ LANGUAGE plpgsql; +select 'delimiter end'; + +select create_index_for_x_trx_log_v2(); +select 'delimiter end'; diff --git a/security-admin/db/sqlanywhere/optimized/current/ranger_core_db_sqlanywhere.sql b/security-admin/db/sqlanywhere/optimized/current/ranger_core_db_sqlanywhere.sql index 9c05513177..157be8e8d6 100644 --- a/security-admin/db/sqlanywhere/optimized/current/ranger_core_db_sqlanywhere.sql +++ b/security-admin/db/sqlanywhere/optimized/current/ranger_core_db_sqlanywhere.sql @@ -1899,6 +1899,8 @@ CREATE NONCLUSTERED INDEX x_resource_up_time ON dbo.x_resource(update_time ASC) GO CREATE NONCLUSTERED INDEX x_trx_log_v2_FK_cr_time ON dbo.x_trx_log_v2(create_time ASC) GO +CREATE NONCLUSTERED INDEX x_trx_log_v2_action ON dbo.x_trx_log_v2(action ASC) +GO CREATE NONCLUSTERED INDEX x_trx_log_v2_FK_added_by_id ON dbo.x_trx_log_v2(added_by_id ASC) GO CREATE NONCLUSTERED INDEX x_trx_log_v2_FK_trx_id ON dbo.x_trx_log_v2(trx_id ASC) diff --git a/security-admin/db/sqlanywhere/patches/075-create-index-for-x_trx_log_v2.sql b/security-admin/db/sqlanywhere/patches/075-create-index-for-x_trx_log_v2.sql new file mode 100644 index 0000000000..8d6d54f636 --- /dev/null +++ b/security-admin/db/sqlanywhere/patches/075-create-index-for-x_trx_log_v2.sql @@ -0,0 +1,23 @@ +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +IF EXISTS(select * from SYS.SYSTABLES where tname = 'x_trx_log_v2') THEN + IF EXISTS(select * from SYS.SYSCOLUMNS where tname = 'x_trx_log_v2' and cname = 'action') THEN + CREATE INDEX IF NOT EXISTS x_trx_log_v2_action ON x_trx_log_v2(action); + END IF; +END IF; +GO + +EXIT \ No newline at end of file diff --git a/security-admin/db/sqlserver/optimized/current/ranger_core_db_sqlserver.sql b/security-admin/db/sqlserver/optimized/current/ranger_core_db_sqlserver.sql index 8aea57bead..ac57f248a1 100644 --- a/security-admin/db/sqlserver/optimized/current/ranger_core_db_sqlserver.sql +++ b/security-admin/db/sqlserver/optimized/current/ranger_core_db_sqlserver.sql @@ -3446,7 +3446,11 @@ CREATE NONCLUSTERED INDEX [x_resource_up_time] ON [x_resource] [update_time] ASC ) WITH (SORT_IN_TEMPDB = OFF,DROP_EXISTING = OFF,IGNORE_DUP_KEY = OFF,ONLINE = OFF) ON [PRIMARY] - +CREATE NONCLUSTERED INDEX [x_trx_log_v2_action] ON [x_trx_log_v2] +( + [action] ASC +) +WITH (SORT_IN_TEMPDB = OFF,DROP_EXISTING = OFF,IGNORE_DUP_KEY = OFF,ONLINE = OFF) ON [PRIMARY] CREATE NONCLUSTERED INDEX [x_trx_log_v2_cr_time] ON [x_trx_log_v2] ( [create_time] ASC diff --git a/security-admin/db/sqlserver/patches/075-create-index-for-x_trx_log_v2.sql b/security-admin/db/sqlserver/patches/075-create-index-for-x_trx_log_v2.sql new file mode 100644 index 0000000000..dedff8d503 --- /dev/null +++ b/security-admin/db/sqlserver/patches/075-create-index-for-x_trx_log_v2.sql @@ -0,0 +1,29 @@ +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +GO +IF OBJECT_ID('x_trx_log_v2') IS NOT NULL +BEGIN + IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'x_trx_log_v2_action' AND object_id = OBJECT_ID('x_trx_log_v2')) + BEGIN + CREATE NONCLUSTERED INDEX [x_trx_log_v2_action] ON [x_trx_log_v2] + ( + [action] ASC + ) + WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY] + END +END +Go + +EXIT; diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerTrxLogV2Service.java b/security-admin/src/main/java/org/apache/ranger/service/RangerTrxLogV2Service.java index 4459cb82d7..94527623b8 100644 --- a/security-admin/src/main/java/org/apache/ranger/service/RangerTrxLogV2Service.java +++ b/security-admin/src/main/java/org/apache/ranger/service/RangerTrxLogV2Service.java @@ -78,6 +78,8 @@ public RangerTrxLogV2Service() { sortFields.add(new SortField("id", "obj.id", true, SortField.SORT_ORDER.DESC)); sortFields.add(new SortField("createDate", "obj.createTime", true, SortField.SORT_ORDER.DESC)); + sortFields.add(new SortField("addedByUserId", "obj.addedByUserId", true, SortField.SORT_ORDER.DESC)); + sortFields.add(new SortField("action", "obj.action", true, SortField.SORT_ORDER.DESC)); } public List getSearchFields() {