Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr: create index #254

Merged
merged 7 commits into from
Jul 9, 2022
Merged

Conversation

cjphaha
Copy link
Member

@cjphaha cjphaha commented Jun 25, 2022

create index statament

@codecov-commenter
Copy link

codecov-commenter commented Jun 25, 2022

Codecov Report

Merging #254 (643c2e9) into master (53b86bc) will decrease coverage by 0.15%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master     #254      +/-   ##
==========================================
- Coverage   37.43%   37.28%   -0.16%     
==========================================
  Files          95       96       +1     
  Lines       13897    13954      +57     
==========================================
  Hits         5203     5203              
- Misses       8044     8101      +57     
  Partials      650      650              
Impacted Files Coverage Δ
pkg/executor/redirect.go 9.69% <0.00%> (ø)
pkg/runtime/ast/ast.go 77.57% <0.00%> (-1.23%) ⬇️
pkg/runtime/ast/create_index.go 0.00% <0.00%> (ø)
pkg/runtime/ast/proto.go 57.14% <ø> (ø)
pkg/runtime/optimize/optimizer.go 23.15% <0.00%> (-0.69%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 53b86bc...643c2e9. Read the comment docs.

}

func (c *CreateIndexStatement) Restore(flag RestoreFlag, sb *strings.Builder, args *[]int) error {
sb.WriteString("CREATE INDEX")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 INDEX 后面不加个 空格吗?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 INDEX 后面不加个 空格吗?

ok~忘记加了

@dongzl
Copy link
Contributor

dongzl commented Jun 26, 2022

ref: #167

@dongzl dongzl added enhancement New feature or request SQL SQL support labels Jun 26, 2022
@cjphaha cjphaha changed the title [WIP]: create index Ftr: create index Jul 2, 2022
}

func (c *CreateIndexStatement) Restore(flag RestoreFlag, sb *strings.Builder, args *[]int) error {
sb.WriteString("CREATE INDEX ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create index has other grammar. This pr only implement the simple grammar?

https://dev.mysql.com/doc/refman/8.0/en/create-index.html

CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name
    [index_type]
    ON tbl_name (key_part,...)
    [index_option]
    [algorithm_option | lock_option] ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this pr just implements the basic syntax, I'm not sure if other grammars are often used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock_option

I suggest we are as consistent as possible with MySQL.

If some grammar is difficult and not common, we are not implemented temporarily.

But some grammars are important, e.g: UNIQUE

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok~

Comment on lines 178 to 184
shard, err := o.computeShards(ru, stmt.Table, nil, args)
if err != nil {
return nil, err
}
if len(shard) == 0 {
return plan.Transparent(stmt, args), nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not the correct way to get shards.

  1. check whether the stmt.Table is a logical table, bypass if not.
  2. enumerate all shards from the logical table topology, see the example code:
		// init shards
		shards := rule.DatabaseTables{}
		// compute all tables
		topology := vt.Topology()
		topology.Each(func(dbIdx, tbIdx int) bool {
			if d, t, ok := topology.Render(dbIdx, tbIdx); ok {
				shards[d] = append(shards[d], t)
			}
			return true
		})

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, may I ask you a question, how to check whether the stmt.Table is a logical table ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the snippet below:

var ru *rule.Rule // prepare your rule
_, ok := ru.VTable("your_table_name")
// target is logical table if ok is true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok~thx

Copy link
Contributor

@jjeffcaii jjeffcaii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls fix

@dongzl dongzl merged commit 6807233 into arana-db:master Jul 9, 2022
Lvnszn pushed a commit to Lvnszn/arana that referenced this pull request Jul 20, 2022
* feat: create index

* fix: add space behind create index restore

* fix: create index add index part spec and tests

* fix: remove unnecessary create index tests

* fix: add create index logic table check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SQL SQL support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants