Help us understand the problem. What is going on with this article?

ActiveAndroidで複合インデックスを構築させる方法

More than 5 years have passed since last update.

通常のindexは以下の通りindex = trueって書いておけば簡単に作れる。

宣言(カラム部分のみ)
@Column(name = "score", index = true)
public int score;
生成されるクエリ(一部)
CREATE INDEX index_XXX_score on XXX(score);

これを複合indexにする場合、組み合わせたいカラム同士で同じ名前をindexGroupsに追加することで複合indexが構築される。

宣言(カラム部分のみ)
@Column(name = "category_id", indexGroups = {"category_score"})
public int categoryId;
@Column(name = "score", indexGroups = {"category_score"})
public int score;
生成されるクエリ(一部)
CREATE INDEX index_XXX_category_score on XXX(category_id, score);

Groups、という名前からお察しの通り、あるカラムを複数のindexに絡めることも可能。例えば、A-BとB-Cの二つの複合indexを使うとか。

例えばこうやってcategoryとscoreで複合indexを設定しておけば、きっと「category = 1をscoreで昇順」みたいなリクエストが爆速になってくれるはず。id取得ばかりがクエリじゃない。ORMはSQLを理解してこそ真の力を発揮できるはず。

YukiAsu
なぜか毎年別言語に取り組み続ける雑食系エンジニア。ここまで来てなんだけど個人的にはScalaが性に合ってた気がする。 PHP->Objective-C->Swift->AndroidSDK->Scala -> Python -> Ruby -> Go
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした