由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - Join optimization
相关主题
How to replace 0 with empty?怎样把SQL一table 中系统自动生成的primary key 改成source table 中 的primary可以?
SQL问题请教: add one more columnOracle Group and Index question
SQL find distinct values in large tableSQL combine two columns from two different tables no shared (转载)
sql server 行转列的问题Table Merge (SQL Server)
两个列联合作Primary Key,还需要单独建index吗?其实有个问题好久没有明白!
请教三个Key的property,analyze 在oracle里怎么用?
SQL combine two tables into one table and add a new columnindexing就是设置primary key吗?
请教是多columns Table的好处?问个external table field definition的问题
相关话题的讨论汇总
话题: domain话题: email话题: key话题: table话题: index
进入Database版参与讨论
1 (共1页)
a*******s
发帖数: 324
1
I have two tables. table email has 1 million records. table domain has 20
records. domain is part of email address.
for example: email: a*******[email protected]
domain: yahoo.com
create table email(email varchar(40) primary key, domain varchar(20), index(
domain));
create table domain(domain varchar(20) primary key);
case1:
select p.email from email p, domain q where p.domain = q.domain
select p.email from email p, domain q where q.domain = p.domain
Is it the same?
Does the databa
B*****g
发帖数: 34098
2
the answer for these questions is "depends".
Without talking about more database structure like index, and without analys
is the real data, can not answer this questions.
但是一般来说,最好不要太依赖database。你是最了解你自己的table的,而不是datab
ase

index(

【在 a*******s 的大作中提到】
: I have two tables. table email has 1 million records. table domain has 20
: records. domain is part of email address.
: for example: email: a*******[email protected]
: domain: yahoo.com
: create table email(email varchar(40) primary key, domain varchar(20), index(
: domain));
: create table domain(domain varchar(20) primary key);
: case1:
: select p.email from email p, domain q where p.domain = q.domain
: select p.email from email p, domain q where q.domain = p.domain

a*******t
发帖数: 891
3
you can see the query excution plan to see how the db engine optimize the
execution
in most cases, it does a good job

index(

【在 a*******s 的大作中提到】
: I have two tables. table email has 1 million records. table domain has 20
: records. domain is part of email address.
: for example: email: a*******[email protected]
: domain: yahoo.com
: create table email(email varchar(40) primary key, domain varchar(20), index(
: domain));
: create table domain(domain varchar(20) primary key);
: case1:
: select p.email from email p, domain q where p.domain = q.domain
: select p.email from email p, domain q where q.domain = p.domain

a*******s
发帖数: 324
4
In MySQL, I use the explain to see how it works.
It seems that primary key has higher priority that index(non primary or
unique keys). It is reasonable.
Thanks

【在 a*******t 的大作中提到】
: you can see the query excution plan to see how the db engine optimize the
: execution
: in most cases, it does a good job
:
: index(

B*****g
发帖数: 34098
5
呵呵,primary key一般都有index

【在 a*******s 的大作中提到】
: In MySQL, I use the explain to see how it works.
: It seems that primary key has higher priority that index(non primary or
: unique keys). It is reasonable.
: Thanks

b*****e
发帖数: 364
6
IN SQL, SET Statistics IO ON, will show the results.
x***e
发帖数: 2449
7

index(
I have to say you need to read some book before posting questions.
Yes, they are the same, cause they are inner joins.
If outer join, it depends.
some recommendations for you.
avoid using varchar as primary key.
try to have ID columns instead.
like email(email_key, email, domain_key)
domain(domain_key, domain)
all key columns should be int,which is the best for index.
domain table does not need primary key or index, since it is just too small.

【在 a*******s 的大作中提到】
: I have two tables. table email has 1 million records. table domain has 20
: records. domain is part of email address.
: for example: email: a*******[email protected]
: domain: yahoo.com
: create table email(email varchar(40) primary key, domain varchar(20), index(
: domain));
: create table domain(domain varchar(20) primary key);
: case1:
: select p.email from email p, domain q where p.domain = q.domain
: select p.email from email p, domain q where q.domain = p.domain

B*****g
发帖数: 34098
8
wk,你们翻老贴。
其实在email table 给domain加个index就行了,1M record也不是很多

20
small.

【在 x***e 的大作中提到】
:
: index(
: I have to say you need to read some book before posting questions.
: Yes, they are the same, cause they are inner joins.
: If outer join, it depends.
: some recommendations for you.
: avoid using varchar as primary key.
: try to have ID columns instead.
: like email(email_key, email, domain_key)
: domain(domain_key, domain)

1 (共1页)
进入Database版参与讨论
相关主题
问个external table field definition的问题两个列联合作Primary Key,还需要单独建index吗?
SQL 2000 create index 問題请教三个Key的property,
多对多relation?SQL combine two tables into one table and add a new column
问一个Oralce index的问题请教是多columns Table的好处?
How to replace 0 with empty?怎样把SQL一table 中系统自动生成的primary key 改成source table 中 的primary可以?
SQL问题请教: add one more columnOracle Group and Index question
SQL find distinct values in large tableSQL combine two columns from two different tables no shared (转载)
sql server 行转列的问题Table Merge (SQL Server)
相关话题的讨论汇总
话题: domain话题: email话题: key话题: table话题: index