Skip to content

Reimplement prepared statements with LRU cache and statement deduplication #618

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
06f7ea5
Initial commit
zainkabani Oct 13, 2023
1cd957e
Cleanup and add stats
zainkabani Oct 13, 2023
af6c2ea
Use an arc instead of full clones to store the parse packets
zainkabani Oct 13, 2023
2247f86
Use mutex instead
zainkabani Oct 13, 2023
d4d88c4
Merge branch 'main' into zain/reimplment-prepared-statements-with-glo…
zainkabani Oct 13, 2023
d2927d0
fmt
zainkabani Oct 13, 2023
fb23e33
clippy
zainkabani Oct 13, 2023
2fb3d4a
fmt
zainkabani Oct 13, 2023
a59aa63
fix?
zainkabani Oct 13, 2023
e2963e9
fix?
zainkabani Oct 13, 2023
8111582
fmt
zainkabani Oct 13, 2023
6e85fb2
typo
zainkabani Oct 13, 2023
46c8f9e
Update docs
zainkabani Oct 14, 2023
9a80b47
Refactor custom protocol
zainkabani Oct 14, 2023
19d8478
fmt
zainkabani Oct 14, 2023
a07874a
move custom protocol handling to before parsing
zainkabani Oct 14, 2023
bf5a39c
Support describe
zainkabani Oct 14, 2023
6a87a68
Add LRU for server side statement cache
zainkabani Oct 14, 2023
b528b95
rename variable
zainkabani Oct 15, 2023
0177af8
Refactoring
zainkabani Oct 15, 2023
cd7942b
Move docs
zainkabani Oct 15, 2023
6205548
Fix test
zainkabani Oct 15, 2023
9cd675e
fix
zainkabani Oct 15, 2023
89e2651
Update tests
zainkabani Oct 16, 2023
d37514f
trigger build
zainkabani Oct 16, 2023
bcce2d5
Add more tests
zainkabani Oct 16, 2023
63aa0c7
Reorder handling sync
zainkabani Oct 17, 2023
e392607
Support when a named describe is sent along with Parse (go pgx) and e…
zainkabani Oct 17, 2023
53880f2
don't talk to client if not needed when client sends Parse
zainkabani Oct 17, 2023
2842c85
fmt :(
zainkabani Oct 17, 2023
5604546
refactor tests
zainkabani Oct 17, 2023
6a1d7f6
nit
zainkabani Oct 17, 2023
a5d4bcf
Reduce hashing
zainkabani Oct 19, 2023
dd021c2
Reducing work done to decode describe and parse messages
zainkabani Oct 19, 2023
116a681
minor refactor
zainkabani Oct 19, 2023
72826e6
Merge branch 'main' into zain/reimplment-prepared-statements-with-glo…
zainkabani Oct 20, 2023
cfe8e9f
Merge branch 'main' into zain/reimplment-prepared-statements-with-glo…
zainkabani Oct 20, 2023
b27c918
Rewrite extended and prepared protocol message handling to better sup…
zainkabani Oct 21, 2023
d107bbe
An attempt to better handle if there are DDL changes that might break…
zainkabani Oct 21, 2023
21b9cde
fix
zainkabani Oct 21, 2023
d791f06
Minor stats fixed and cleanup
zainkabani Oct 21, 2023
a57550d
Cosmetic fixes (#64)
levkk Oct 23, 2023
db70499
Change server drop for statement cache error to a `deallocate all`
zainkabani Oct 23, 2023
7fa1147
Updated comments and added new idea for handling DDL changes impactin…
zainkabani Oct 23, 2023
005029d
fix test?
zainkabani Oct 23, 2023
6928d31
Revert test change
zainkabani Oct 23, 2023
b889b4b
trigger build, flakey test
zainkabani Oct 23, 2023
0dd5e88
Avoid potential race conditions by changing get_or_insert to promote …
zainkabani Oct 24, 2023
962090a
remove ps enabled variable on the server in favor of using an option
zainkabani Oct 24, 2023
80aa607
Add close to the Extended Protocol buffer
zainkabani Oct 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,22 +259,6 @@ Password to be used for connecting to servers to obtain the hash used for md5 au
specified in `auth_query_user`. The connection will be established using the database configured in the pool.
This parameter is inherited by every pool and can be redefined in pool configuration.

### prepared_statements
```
path: general.prepared_statements
default: false
```

Whether to use prepared statements or not.

### prepared_statements_cache_size
```
path: general.prepared_statements_cache_size
default: 500
```

Size of the prepared statements cache.

### dns_cache_enabled
```
path: general.dns_cache_enabled
Expand Down Expand Up @@ -324,6 +308,15 @@ If the client doesn't specify, PgCat routes traffic to this role by default.
`replica` round-robin between replicas only without touching the primary,
`primary` all queries go to the primary unless otherwise specified.

### prepared_statements_cache_size
```
path: general.prepared_statements_cache_size
default: 0
```

Size of the prepared statements cache. 0 means disabled.
TODO: update documentation

### query_parser_enabled
```
path: pools.<pool_name>.query_parser_enabled
Expand Down
31 changes: 31 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ itertools = "0.10"
clap = { version = "4.3.1", features = ["derive", "env"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["json", "env-filter", "std"]}
lru = "0.12.0"

[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = "0.5.0"
Expand Down
10 changes: 4 additions & 6 deletions pgcat.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ tcp_keepalives_count = 5
# Number of seconds between keepalive packets.
tcp_keepalives_interval = 5

# Handle prepared statements.
prepared_statements = true

# Prepared statements server cache size.
prepared_statements_cache_size = 500

# Path to TLS Certificate file to use for TLS connections
# tls_certificate = ".circleci/server.cert"
# Path to TLS private key file to use for TLS connections
Expand Down Expand Up @@ -156,6 +150,10 @@ load_balancing_mode = "random"
# `primary` all queries go to the primary unless otherwise specified.
default_role = "any"

# Prepared statements cache size.
# TODO: update documentation
prepared_statements_cache_size = 500

# If Query Parser is enabled, we'll attempt to parse
# every incoming query to determine if it's a read or a write.
# If it's a read query, we'll direct it to a replica. Otherwise, if it's a write,
Expand Down
5 changes: 5 additions & 0 deletions src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ where
("age_seconds", DataType::Numeric),
("prepare_cache_hit", DataType::Numeric),
("prepare_cache_miss", DataType::Numeric),
("prepare_cache_eviction", DataType::Numeric),
("prepare_cache_size", DataType::Numeric),
];

Expand Down Expand Up @@ -776,6 +777,10 @@ where
.prepared_miss_count
.load(Ordering::Relaxed)
.to_string(),
server
.prepared_eviction_count
.load(Ordering::Relaxed)
.to_string(),
server
.prepared_cache_size
.load(Ordering::Relaxed)
Expand Down
Loading