database-design

Storing “redundant” foreign keys to avoid joins

纵然是瞬间 提交于 2021-02-08 10:13:10
问题 I'm designing a database for a web application project and I came to the conclusion I may have few queries that will require a lot of joined tables to just make one check. I'm wondering how bad is it to store the foreign key somewhere on the way to decrease number of joins required for these queries? To give you an example of what I have at this moment: Service => Booking => Transaction => Wallet => BonusOffer I need to check whether the service has been bought with wallet associated with a

Group dependency SQL design

空扰寡人 提交于 2021-02-08 10:12:46
问题 I have an entity which has NOT NULL requirements based on the group it belongs to. For instance... There are three types of churches: Buddhist, Muslim, and Christian. All churches have some common required properties, however, each type of church has additional required properties. All people have some common required properties, however, they have additional required properties based on the church type they belong to. People must belong to one and only one church, however, may change their

Storing “redundant” foreign keys to avoid joins

纵然是瞬间 提交于 2021-02-08 10:12:27
问题 I'm designing a database for a web application project and I came to the conclusion I may have few queries that will require a lot of joined tables to just make one check. I'm wondering how bad is it to store the foreign key somewhere on the way to decrease number of joins required for these queries? To give you an example of what I have at this moment: Service => Booking => Transaction => Wallet => BonusOffer I need to check whether the service has been bought with wallet associated with a

Group dependency SQL design

空扰寡人 提交于 2021-02-08 10:10:10
问题 I have an entity which has NOT NULL requirements based on the group it belongs to. For instance... There are three types of churches: Buddhist, Muslim, and Christian. All churches have some common required properties, however, each type of church has additional required properties. All people have some common required properties, however, they have additional required properties based on the church type they belong to. People must belong to one and only one church, however, may change their

Changing a primary key to a composite primary key

橙三吉。 提交于 2021-02-08 09:41:34
问题 I've been using a "normal" (non-composite) primary key for one of my tables. Now I want to change it to a composite primary key. My tables look something like this: -- Table 1 CREATE TABLE foo ( id SERIAL PRIMARY KEY, id2 INT, ... ) -- Table 2 CREATE TABLE bar ( id SERIAL PRIMARY KEY, id_foo INT REFERENCES foo (id) ) The problem here is that psql does not want to drop the old primary key, since other tables reference it. Is there any way of getting around this without dropping the whole

How to store large number of records in MySql database?

早过忘川 提交于 2021-02-08 09:20:10
问题 I have a table which consists of around 2500 rows for a single user id. And for each user id, same number of rows will be there. If number of users increase then I am afraid number of rows will be vast. So can you please suggest me what to do ? Should I use different tables for different users or a single table for all users. And another thing , is there any limitation of how many maximum number rows/columns can be there in a single table ? My database looks like below structure : for User1

Multiple vs single database

╄→尐↘猪︶ㄣ 提交于 2021-02-08 08:56:18
问题 We are developing a new version of our web application. We have multiple clients (500+), each client has its own database with its own data: users, products... In the new version, all clients are going to share some data, for example, users are going to be in the platform but each client will be able to access to their users only, but instead of having the users for each client we want to have all the users in a centralize table. Other things such as products, orders...are going to belong to

Confused about Sequelize associations

喜夏-厌秋 提交于 2021-02-08 06:57:25
问题 I just found Sequelize as a good ORM framework to use in my node + MySQL webapp. But when I was designing my database tables, I got so confused about Sequelize associations. Just think about user and system notification in a webapp as a very simple case: The site has many users The site would send notifications to some or every users, and the same notification just save as one record Users could know any notification he/she received is read or not(by a read date) Then I design 3 tables as

How to ensure entries with non-overlapping time ranges?

橙三吉。 提交于 2021-02-08 05:16:26
问题 I need to ensure my database only contains entries where two or more of its columns are unique. This can easily be achieved with a UNIQUE constraint over those columns. In my case, I need to forbid duplication only for overlapping time ranges. The table has valid_from and valid_to columns. In some cases one might first need to expire the active entry to by setting valid_to = now , and then inserting a new entry adjusted to valid_from = now and valid_to = infinity . I seem to be able to expire

Postgresql 9.4 query gets progressively slower when joining TSTZRANGE with &&

感情迁移 提交于 2021-02-07 12:19:45
问题 I am running a query that gets progressively slower as records are added. Records are added continuously via an automated process (bash calling psql). I would like to correct this bottle neck; however, I don't know what my best option is. This is the output from pgBadger: Hour Count Duration Avg duration 00 9,990 10m3s 60ms <---ignore this hour 02 1 60ms 60ms <---ignore this hour 03 4,638 1m54s 24ms <---queries begin with table empty 04 30,991 55m49s 108ms <---first full hour of queries