Home>
About Rails composite indexes.
For the book i am learning (Perfect Rails) for the following code
Intermediate table for User to participate in #Event
def change
create_table: tickets do | t |
t.references: user
t.references: event, null: false, foreign_key: true, index: false
t.string: comment
t.timestamps
end
add_index: tickets, [: event_id,: user_id], unique: true
end
end
Since the composite index is set to: event_id->: user_id,
Added index: false because a single index by the references method is unnecessary.
It is only stated that
If I put a composite index on two references, should I put a single index on the latter (: user_id)?
-
Answer # 1
Related articles
- ruby on rails - about saving comments
- ruby on rails - about request spec of rspec about test code at login
- about description of manifest file of ruby on rails
- ruby - about how to save db with rails devise
- ruby on rails - about the legitimacy of db design
- ruby on rails - about image distribution on heroku and s3
- ruby - [rails] about nameerror
- about validation of ruby on rails
- ruby on rails - about switching screen display on multiple models
- ruby on rails - about the description in applicationjs
- ruby on rails 5 - error about rails where method
- ruby on rails 6 - rails tutorial chapter 14 about follow, unfollow, following? methods
- ruby on rails - about matters that cannot be migrated
- ruby - about the delete function in rails
- ruby on rails - about primary key/natural key/surrogate key in db design
- ruby - about rails controller new action
- ruby on rails 6 - about rails error "wrong number of arguments (given 1, expected 0)"
- ruby - about rails routing
- ruby - about embedding rails videos
Trends
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
If you want to use a foreign key, you have to put it up.
event_id, user_id
In the case of a composite index calledevent_id
You can use this index for just a search,user_id
The index does not work for just searching. On the other hand, you need an index to apply a foreign key.