From d5e619d4bb33030db19172bf2e120ebe55310b21 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Tue, 23 May 2023 20:22:59 +0900 Subject: [PATCH] Remove OPTIMIZER_FEATURES_ENABLE('11.2.0.2') hint take 2 There were some unremoved hints via #2337 --- .../oracle_enhanced/schema_dumper.rb | 2 +- .../oracle_enhanced/schema_statements.rb | 26 +++++++------- .../oracle_enhanced/structure_dump.rb | 34 +++++++++---------- .../oracle_enhanced_adapter.rb | 12 +++---- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb b/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb index 637c4e877..dfec7e952 100644 --- a/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +++ b/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb @@ -181,7 +181,7 @@ def default_primary_key?(column) def extract_expression_for_virtual_column(column) column_name = column.name @connection.select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect - select /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ data_default from all_tab_columns + select data_default from all_tab_columns where owner = SYS_CONTEXT('userenv', 'current_schema') and table_name = :table_name and column_name = :column_name diff --git a/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb b/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb index a111a828a..8ddf1d022 100644 --- a/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +++ b/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb @@ -12,7 +12,7 @@ module SchemaStatements def tables # :nodoc: select_values(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ + SELECT DECODE(table_name, UPPER(table_name), LOWER(table_name), table_name) FROM all_tables WHERE owner = SYS_CONTEXT('userenv', 'current_schema') @@ -45,7 +45,7 @@ def table_exists?(table_name) end select_values(<<~SQL.squish, "SCHEMA", [bind_string("owner", table_owner), bind_string("table_name", table_name)]).any? - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ owner, table_name + SELECT owner, table_name FROM all_tables WHERE owner = :owner AND table_name = :table_name @@ -61,14 +61,14 @@ def data_source_exists?(table_name) def views # :nodoc: select_values(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ + SELECT LOWER(view_name) FROM all_views WHERE owner = SYS_CONTEXT('userenv', 'current_schema') SQL end def materialized_views # :nodoc: select_values(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ + SELECT LOWER(mview_name) FROM all_mviews WHERE owner = SYS_CONTEXT('userenv', 'current_schema') SQL end @@ -91,7 +91,7 @@ def indexes(table_name) # :nodoc: default_tablespace_name = default_tablespace result = select_all(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name)]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ LOWER(i.table_name) AS table_name, LOWER(i.index_name) AS index_name, i.uniqueness, + SELECT LOWER(i.table_name) AS table_name, LOWER(i.index_name) AS index_name, i.uniqueness, i.index_type, i.ityp_owner, i.ityp_name, i.parameters, LOWER(i.tablespace_name) AS tablespace_name, LOWER(c.column_name) AS column_name, e.column_expression, @@ -121,7 +121,7 @@ def indexes(table_name) # :nodoc: if row["index_type"] == "DOMAIN" && row["ityp_owner"] == "CTXSYS" && row["ityp_name"] == "CONTEXT" procedure_name = default_datastore_procedure(row["index_name"]) source = select_values(<<~SQL.squish, "SCHEMA", [bind_string("procedure_name", procedure_name.upcase)]).join - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ text + SELECT text FROM all_source WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND name = :procedure_name @@ -370,7 +370,7 @@ def index_name(table_name, options) # :nodoc: def index_name_exists?(table_name, index_name) (_owner, table_name) = @raw_connection.describe(table_name) result = select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name), bind_string("index_name", index_name.to_s.upcase)]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ 1 FROM all_indexes i + SELECT 1 FROM all_indexes i WHERE i.owner = SYS_CONTEXT('userenv', 'current_schema') AND i.table_owner = SYS_CONTEXT('userenv', 'current_schema') AND i.table_name = :table_name @@ -513,7 +513,7 @@ def table_comment(table_name) # :nodoc: # TODO (_owner, table_name) = @raw_connection.describe(table_name) select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name)]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ comments FROM all_tab_comments + SELECT comments FROM all_tab_comments WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND table_name = :table_name SQL @@ -529,7 +529,7 @@ def column_comment(table_name, column_name) # :nodoc: # TODO: it does not exist in Abstract adapter (_owner, table_name) = @raw_connection.describe(table_name) select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name), bind_string("column_name", column_name.upcase)]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ comments FROM all_col_comments + SELECT comments FROM all_col_comments WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND table_name = :table_name AND column_name = :column_name @@ -546,7 +546,7 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, **) # :nodoc: def tablespace(table_name) select_value(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ tablespace_name + SELECT tablespace_name FROM all_tables WHERE table_name='#{table_name.to_s.upcase}' AND owner = SYS_CONTEXT('userenv', 'current_schema') @@ -558,7 +558,7 @@ def foreign_keys(table_name) # :nodoc: (_owner, desc_table_name) = @raw_connection.describe(table_name) fk_info = select_all(<<~SQL.squish, "SCHEMA", [bind_string("desc_table_name", desc_table_name)]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ r.table_name to_table + SELECT r.table_name to_table ,rc.column_name references_column ,cc.column_name ,c.constraint_name name @@ -600,7 +600,7 @@ def extract_foreign_key_action(specifier) # :nodoc: def disable_referential_integrity(&block) # :nodoc: old_constraints = select_all(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ constraint_name, owner, table_name + SELECT constraint_name, owner, table_name FROM all_constraints WHERE constraint_type = 'R' AND status = 'ENABLED' @@ -715,7 +715,7 @@ def rebuild_primary_key_index_to_default_tablespace(table_name, options) return unless tablespace index_name = select_value(<<~SQL.squish, "Index name for primary key", [bind_string("table_name", table_name.upcase)]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ index_name FROM all_constraints + SELECT index_name FROM all_constraints WHERE table_name = :table_name AND constraint_type = 'P' AND owner = SYS_CONTEXT('userenv', 'current_schema') diff --git a/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb b/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb index eb6835f19..018921ddd 100644 --- a/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +++ b/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb @@ -9,7 +9,7 @@ module StructureDump # :nodoc: def structure_dump # :nodoc: sequences = select(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ + SELECT sequence_name, min_value, max_value, increment_by, order_flag, cycle_flag FROM all_sequences where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1 @@ -19,7 +19,7 @@ def structure_dump # :nodoc: "CREATE SEQUENCE #{quote_table_name(result["sequence_name"])} MINVALUE #{result["min_value"]} MAXVALUE #{result["max_value"]} INCREMENT BY #{result["increment_by"]} #{result["order_flag"] == 'Y' ? "ORDER" : "NOORDER"} #{result["cycle_flag"] == 'Y' ? "CYCLE" : "NOCYCLE"}" end tables = select_values(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables t + SELECT table_name FROM all_tables t WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N' AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv WHERE mv.owner = t.owner AND mv.mview_name = t.table_name) @@ -31,7 +31,7 @@ def structure_dump # :nodoc: virtual_columns = virtual_columns_for(table_name) if supports_virtual_columns? ddl = +"CREATE#{ ' GLOBAL TEMPORARY' if temporary_table?(table_name)} TABLE \"#{table_name}\" (\n" columns = select_all(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name)]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name, data_type, data_length, char_used, char_length, + SELECT column_name, data_type, data_length, char_used, char_length, data_precision, data_scale, data_default, nullable FROM all_tab_columns WHERE table_name = :table_name @@ -92,7 +92,7 @@ def structure_dump_virtual_column(column, data_default) # :nodoc: def structure_dump_primary_key(table) # :nodoc: opts = { name: "", cols: [] } pks = select_all(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ a.constraint_name, a.column_name, a.position + SELECT a.constraint_name, a.column_name, a.position FROM all_cons_columns a JOIN all_constraints c ON a.constraint_name = c.constraint_name @@ -111,7 +111,7 @@ def structure_dump_primary_key(table) # :nodoc: def structure_dump_unique_keys(table) # :nodoc: keys = {} uks = select_all(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ a.constraint_name, a.column_name, a.position + SELECT a.constraint_name, a.column_name, a.position FROM all_cons_columns a JOIN all_constraints c ON a.constraint_name = c.constraint_name @@ -147,7 +147,7 @@ def structure_dump_indexes(table_name) # :nodoc: def structure_dump_fk_constraints # :nodoc: foreign_keys = select_all(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables + SELECT table_name FROM all_tables WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1 SQL fks = foreign_keys.map do |table| @@ -175,7 +175,7 @@ def structure_dump_table_comments(table_name) def structure_dump_column_comments(table_name) comments = [] columns = select_values(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name)]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name FROM all_tab_columns + SELECT column_name FROM all_tab_columns WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND table_name = :table_name ORDER BY column_id SQL @@ -210,7 +210,7 @@ def foreign_key_definition(to_table, options = {}) # :nodoc: def structure_dump_db_stored_code # :nodoc: structure = [] all_source = select_all(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ DISTINCT name, type + SELECT DISTINCT name, type FROM all_source WHERE type IN ('PROCEDURE', 'PACKAGE', 'PACKAGE BODY', 'FUNCTION', 'TRIGGER', 'TYPE') AND name NOT LIKE 'BIN$%' @@ -219,7 +219,7 @@ def structure_dump_db_stored_code # :nodoc: all_source.each do |source| ddl = +"CREATE OR REPLACE \n" texts = select_all(<<~SQL.squish, "all source at structure dump", [bind_string("source_name", source["name"]), bind_string("source_type", source["type"])]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ text + SELECT text FROM all_source WHERE name = :source_name AND type = :source_type @@ -242,7 +242,7 @@ def structure_dump_db_stored_code # :nodoc: def structure_dump_views # :nodoc: structure = [] views = select_all(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ view_name, text FROM all_views + SELECT view_name, text FROM all_views WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY view_name ASC SQL views.each do |view| @@ -254,7 +254,7 @@ def structure_dump_views # :nodoc: def structure_dump_synonyms # :nodoc: structure = [] synonyms = select_all(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ owner, synonym_name, table_name, table_owner + SELECT owner, synonym_name, table_name, table_owner FROM all_synonyms WHERE owner = SYS_CONTEXT('userenv', 'current_schema') SQL @@ -267,14 +267,14 @@ def structure_dump_synonyms # :nodoc: def structure_drop # :nodoc: sequences = select_values(<<~SQL.squish, "SCHEMA") - SELECT/*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ + SELECT sequence_name FROM all_sequences where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1 SQL statements = sequences.map do |seq| "DROP SEQUENCE \"#{seq}\"" end tables = select_values(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name from all_tables t + SELECT table_name from all_tables t WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N' AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv WHERE mv.owner = t.owner AND mv.mview_name = t.table_name) @@ -290,7 +290,7 @@ def structure_drop # :nodoc: def temp_table_drop # :nodoc: temporary_tables = select_values(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables + SELECT table_name FROM all_tables WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N' AND temporary = 'Y' ORDER BY 1 SQL @@ -324,7 +324,7 @@ def execute_structure_dump(string) # return [{'column_name' => 'FOOS', 'data_default' => '...'}, ...] def virtual_columns_for(table) select_all(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table.upcase)]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name, data_default + SELECT column_name, data_default FROM all_tab_cols WHERE virtual_column = 'YES' AND owner = SYS_CONTEXT('userenv', 'current_schema') @@ -335,7 +335,7 @@ def virtual_columns_for(table) def drop_sql_for_feature(type) short_type = type == "materialized view" ? "mview" : type features = select_values(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ #{short_type}_name FROM all_#{short_type.tableize} + SELECT #{short_type}_name FROM all_#{short_type.tableize} where owner = SYS_CONTEXT('userenv', 'current_schema') SQL statements = features.map do |name| @@ -346,7 +346,7 @@ def drop_sql_for_feature(type) def drop_sql_for_object(type) objects = select_values(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ object_name FROM all_objects + SELECT object_name FROM all_objects WHERE object_type = '#{type.upcase}' and owner = SYS_CONTEXT('userenv', 'current_schema') SQL statements = objects.map do |name| diff --git a/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb b/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb index e889cd301..b5d9551f3 100644 --- a/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +++ b/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb @@ -571,7 +571,7 @@ def current_schema # Default tablespace name of current user def default_tablespace select_value(<<~SQL.squish, "SCHEMA") - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ LOWER(default_tablespace) FROM user_users + SELECT LOWER(default_tablespace) FROM user_users WHERE username = SYS_CONTEXT('userenv', 'current_schema') SQL end @@ -580,7 +580,7 @@ def column_definitions(table_name) (owner, desc_table_name) = @raw_connection.describe(table_name) select_all(<<~SQL.squish, "SCHEMA", [bind_string("owner", owner), bind_string("table_name", desc_table_name)]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ cols.column_name AS name, cols.data_type AS sql_type, + SELECT cols.column_name AS name, cols.data_type AS sql_type, cols.data_default, cols.nullable, cols.virtual_column, cols.hidden_column, cols.data_type_owner AS sql_type_owner, DECODE(cols.data_type, 'NUMBER', data_precision, @@ -612,7 +612,7 @@ def pk_and_sequence_for(table_name, owner = nil, desc_table_name = nil) # :nodoc (owner, desc_table_name) = @raw_connection.describe(table_name) seqs = select_values_forcing_binds(<<~SQL.squish, "SCHEMA", [bind_string("owner", owner), bind_string("sequence_name", default_sequence_name(desc_table_name))]) - select /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ us.sequence_name + select us.sequence_name from all_sequences us where us.sequence_owner = :owner and us.sequence_name = upper(:sequence_name) @@ -620,7 +620,7 @@ def pk_and_sequence_for(table_name, owner = nil, desc_table_name = nil) # :nodoc # changed back from user_constraints to all_constraints for consistency pks = select_values_forcing_binds(<<~SQL.squish, "SCHEMA", [bind_string("owner", owner), bind_string("table_name", desc_table_name)]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ cc.column_name + SELECT cc.column_name FROM all_constraints c, all_cons_columns cc WHERE c.owner = :owner AND c.table_name = :table_name @@ -654,7 +654,7 @@ def primary_keys(table_name) # :nodoc: (_owner, desc_table_name) = @raw_connection.describe(table_name) pks = select_values_forcing_binds(<<~SQL.squish, "SCHEMA", [bind_string("table_name", desc_table_name)]) - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ cc.column_name + SELECT cc.column_name FROM all_constraints c, all_cons_columns cc WHERE c.owner = SYS_CONTEXT('userenv', 'current_schema') AND c.table_name = :table_name @@ -684,7 +684,7 @@ def columns_for_distinct(columns, orders) # :nodoc: def temporary_table?(table_name) # :nodoc: select_value_forcing_binds(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name.upcase)]) == "Y" - SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ + SELECT temporary FROM all_tables WHERE table_name = :table_name and owner = SYS_CONTEXT('userenv', 'current_schema') SQL end