在 Oracle 中,为什么在删除表分区时公共同义词会失效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/441021/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:41:10  来源:igfitidea点击:

In Oracle, why do public synonyms become invalid when a table partition is dropped

sqloracledatabase-partitioningsynonym

提问by Jamie Love

can someone tell me why the following behavior occurs (Oracle 10.2):

有人可以告诉我为什么会发生以下行为(Oracle 10.2):

SQL> create table part_test (
        i int primary key,
        d date
)
partition by range (d) (partition part_test_1 values less than (to_date('  2    3    4    5  1980-01-01', 'yyyy-mm-dd')));

create public synonym part_test for part_test;

select object_name, object_type, status from all_objects where object_name = 'PART_TEST';

alter table part_test add partition part_test_2 values less than (to_date('1981-01-01', 'yyyy-mm-dd'));

select object_name, object_type, status from all_objects where object_name = 'PART_TEST';

alter table part_test drop partition part_test_1;

select object_name, object_type, status from all_objects where object_name = 'PART_TEST';

drop public synonym part_test;
drop table part_test;

Table created.

SQL> SQL> 
Synonym created.

SQL> SQL> 
OBJECT_NAME                    OBJECT_TYPE         STATUS
------------------------------ ------------------- -------
PART_TEST                      TABLE               VALID
PART_TEST                      TABLE PARTITION     VALID
PART_TEST                      SYNONYM             VALID

SQL> SQL> 
Table altered.

SQL> SQL> 
OBJECT_NAME                    OBJECT_TYPE         STATUS
------------------------------ ------------------- -------
PART_TEST                      TABLE               VALID
PART_TEST                      TABLE PARTITION     VALID
PART_TEST                      TABLE PARTITION     VALID
PART_TEST                      SYNONYM             VALID

SQL> SQL> 
Table altered.

SQL> SQL> 
OBJECT_NAME                    OBJECT_TYPE         STATUS
------------------------------ ------------------- -------
PART_TEST                      TABLE               VALID
PART_TEST                      TABLE PARTITION     VALID
PART_TEST                      SYNONYM             INVALID

SQL> SQL> 
Synonym dropped.

SQL> 
Table dropped.

SQL> 

The synonym becomes invalid after partitions are dropped, and I can't work out why.

删除分区后同义词变得无效,我不知道为什么。

Thanks for any thoughts.

感谢您的任何想法。

回答by tuinstoel

I have tested it with Oracle 10.2 and the synonym becomes indeed invalid but when an other user uses the synonym by doing

我已经用 Oracle 10.2 对其进行了测试,同义词确实变得无效,但是当其他用户通过执行该同义词使用该同义词时

select count(*) from part_test;

从 part_test 中选择 count(*);

Oracle automatically compiles the synonym and the synonym becomes valid.

Oracle 自动编译同义词,同义词变为有效。

It is the same with packages, procedures and functions. When you execute them and they are invalid, Oracle will try to compile them automatically.

包、过程和函数也是如此。当您执行它们并且它们无效时,Oracle 将尝试自动编译它们。

回答by Gary Myers

It doesn't in 11.1.0.6 It could have been a bug that was fixed. It may have been something that was necessary (eg for revalidating a view based on a synonym...) but where an improved technique has been used.

它不在 11.1.0.6 中它可能是一个已修复的错误。它可能是必要的(例如,根据同义词重新验证视图...),但使用了改进的技术。