Redian新闻
>
问一个Oralce index的问题
avatar
问一个Oralce index的问题# Database - 数据库
y*o
1
比如说:
select last_name from employees where upper(last_name) like 'JO%';
有没有创建一个index在last_name上,我们肉眼根本看不出区别的吧,是不是?
avatar
t*g
2
select * from all_indexes where table_name = EMPLOYEES
avatar
y*o
3
I don't know what you are suggesting, though.
I did find the index I created in all_indexes:
OWNER INDEX_NAME INDEX_TYPE TABLE_OWNER TABLE_NAME
avatar
q*1
4
MySQL一般用explain
explain select last_name from employees where ******;
会输出一个表,可以看出你的 SQL 命令到底有没有用到indexes

【在 y********o 的大作中提到】
: 比如说:
: select last_name from employees where upper(last_name) like 'JO%';
: 有没有创建一个index在last_name上,我们肉眼根本看不出区别的吧,是不是?

avatar
y*o
5
噢,这个我知道,在Oracle里面做:
set autotrace on explain
我可以看到oracle 确实用了lastnameindex:
avatar
y*o
6
其实我不太懂oracle的这个 execution plan.

(
2
2

【在 y********o 的大作中提到】
: 噢,这个我知道,在Oracle里面做:
: set autotrace on explain
: 我可以看到oracle 确实用了lastnameindex:

avatar
s*o
7
You actually don't have any benefit of index by using 'like'.
If you use select * from employees where upper(last_name) like 'JO%';
It will be gaurantee a full table access.
In your statement,
select last_name from employees where upper(last_name) like 'JO%';
Most likely, if you have an index built on last_name, you will have full
index scan which doesn't do any better performance.
avoid to use 'like' unless you absolutely have to or the table is small and
it's definitely not scalable in the fut

【在 y********o 的大作中提到】
: 比如说:
: select last_name from employees where upper(last_name) like 'JO%';
: 有没有创建一个index在last_name上,我们肉眼根本看不出区别的吧,是不是?

avatar
y*o
8
So, we will only benefit from index if we use the equal operator (=), right?

and

【在 s**o 的大作中提到】
: You actually don't have any benefit of index by using 'like'.
: If you use select * from employees where upper(last_name) like 'JO%';
: It will be gaurantee a full table access.
: In your statement,
: select last_name from employees where upper(last_name) like 'JO%';
: Most likely, if you have an index built on last_name, you will have full
: index scan which doesn't do any better performance.
: avoid to use 'like' unless you absolutely have to or the table is small and
: it's definitely not scalable in the fut

avatar
q*1
9
I think the main problem is the upper() function, since you indexed
the value of "last_name" instead of the value of upper(last_name).
"like" clause should be OK. coz you use "A%" instead of "%A" or
"%A%", you can use index anyway.
my 2 cents,

right?

【在 y********o 的大作中提到】
: So, we will only benefit from index if we use the equal operator (=), right?
:
: and

avatar
y*o
10
Saho, your 2 cents are in order.

【在 q**1 的大作中提到】
: I think the main problem is the upper() function, since you indexed
: the value of "last_name" instead of the value of upper(last_name).
: "like" clause should be OK. coz you use "A%" instead of "%A" or
: "%A%", you can use index anyway.
: my 2 cents,
:
: right?

avatar
q*1
11
that is for MySQL, I dont know Oracle..They may have very
different indexing strategies.

【在 y********o 的大作中提到】
: Saho, your 2 cents are in order.
avatar
s*o
12
you are right on that. 'A%' is a little bit special, you will get a index
range scan. The statement give him an index full scan due to "Select last_
name from ...". It will give a index range scan if the upper() function
index is built or the upper() clause is removed.

【在 q**1 的大作中提到】
: I think the main problem is the upper() function, since you indexed
: the value of "last_name" instead of the value of upper(last_name).
: "like" clause should be OK. coz you use "A%" instead of "%A" or
: "%A%", you can use index anyway.
: my 2 cents,
:
: right?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。