Skip to content

Commit

Permalink
JAMES-2586 ADR for Posgres mailbox tables structure (linagora#1857)
Browse files Browse the repository at this point in the history
  • Loading branch information
hungphan227 authored and vttranlina committed Apr 14, 2024
1 parent 1fd869f commit ab25d72
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/adr/0070-postgresql-adoption.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 68. Native PostgreSQL adoption
# 70. Native PostgreSQL adoption

Date: 2023-10-31

Expand Down
58 changes: 58 additions & 0 deletions src/adr/0071-postgresql-mailbox-tables-structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 71. Postgresql Mailbox tables structure

Date: 2023-12-14

## Status

Implemented

## Context

As described in [ADR-70](link), we are willing to provide a Postgres implementation for Apache James.
The current document is willing to detail the inner working of the mailbox of the target implementation.

## Decision

![diagram for mailbox tables](img/adr-71-mailbox-tables-diagram.png)

Table list:
- mailbox
- mailbox_annotations
- message
- message_mailbox
- subscription

Indexes in table message_mailbox:
- message_mailbox_message_id_index (message_id)
- mailbox_id_mail_uid_index (mailbox_id, message_uid)
- mailbox_id_is_seen_mail_uid_index (mailbox_id, is_seen, message_uid)
- mailbox_id_is_recent_mail_uid_index (mailbox_id, is_recent, message_uid)
- mailbox_id_is_delete_mail_uid_index (mailbox_id, is_deleted, message_uid)

Indexes are used to find records faster.

The table structure is mostly normalized which mitigates storage costs and achieves consistency easily.

Foreign key constraints (mailbox_id in mailbox_annotations, message_id in message_mailbox) help to ensure data consistency. For example, message_id 1 in table message_mailbox could not exist if message_id 1 in table message does not exist

For some fields, hstore data type are used. Hstore is key-value hashmap data structure. Hstore allows us to model complex data types without the need for complex joins.

Special postgres clauses such as RETURNING, ON CONFLICT are used to ensure consistency without the need of combining multiple queries in a single transaction.

## Consequences

Pros:
- Indexes could increase query performance significantly

Cons:
- Too many indexes in a table could reduce the performance of updating data in the table

## Alternatives

## References

- [JIRA](https://issues.apache.org/jira/browse/JAMES-2586)
- [PostgreSQL](https://www.postgresql.org/)



Binary file added src/adr/img/adr-71-mailbox-tables-diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ab25d72

Please sign in to comment.