Skip to content

Prepared statements settings

lain requested to merge prepared-statements-settings into develop

This makes ecto write unnamed prepared queries, which loses the caching, but enables custom plans for all queries even on postgres < 12.

This gives a similar performance boost as setting the force_custom_plan option. Here's a benchmark for the !2223 (closed) MR with this applied:

RUM enabled: false

11:00:51.358 [warn]  Found files in the emoji folder. These will be ignored, please move them to a subdirectory
Found files: test.png
Found 200000 activities, won't generate new ones
Database contains 67 posts tagged with tag_0
Database contains 300 posts tagged with tag_1
Database contains 617 posts tagged with tag_2
Database contains 1131 posts tagged with tag_3
Database contains 1788 posts tagged with tag_4
Database contains 2405 posts tagged with tag_5
Database contains 3453 posts tagged with tag_6
Database contains 4475 posts tagged with tag_7
Database contains 5581 posts tagged with tag_8
Database contains 6963 posts tagged with tag_9
Database contains 8338 posts tagged with tag_10
Database contains 9888 posts tagged with tag_11
Database contains 11871 posts tagged with tag_12
Database contains 13516 posts tagged with tag_13
Database contains 15762 posts tagged with tag_14
Database contains 17973 posts tagged with tag_15
Database contains 20025 posts tagged with tag_16
Database contains 22702 posts tagged with tag_17
Database contains 25092 posts tagged with tag_18
Database contains 28053 posts tagged with tag_19
Database contains 0 posts tagged with tag_20
Not all of your protocols have been consolidated. In order to achieve the
best possible accuracy for benchmarks, please ensure protocol
consolidation is enabled in your benchmarking environment.

Operating System: Linux
CPU Information: AMD Ryzen Threadripper 3970X 32-Core Processor
Number of Available Cores: 64
Available memory: 62.73 GB
Elixir 1.9.4
Erlang 22.2.6

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 0 ns
parallel: 1
inputs: For #tag_0, For #tag_1, For #tag_2, For #tag_3, For #tag_4, For #tag_5, For #tag_6, For #tag_7, For #tag_8, For #tag_9, For #tag_10, For #tag_11, For #tag_12, For #tag_13, For #tag_14, For #tag_15, For #tag_16, For #tag_17, For #tag_18, For #tag_19, For #tag_20
Estimated total run time: 2.45 min

Benchmarking Hashtag fetching with input For #tag_0...
Benchmarking Hashtag fetching with input For #tag_1...
Benchmarking Hashtag fetching with input For #tag_2...
Benchmarking Hashtag fetching with input For #tag_3...
Benchmarking Hashtag fetching with input For #tag_4...
Benchmarking Hashtag fetching with input For #tag_5...
Benchmarking Hashtag fetching with input For #tag_6...
Benchmarking Hashtag fetching with input For #tag_7...
Benchmarking Hashtag fetching with input For #tag_8...
Benchmarking Hashtag fetching with input For #tag_9...
Benchmarking Hashtag fetching with input For #tag_10...
Benchmarking Hashtag fetching with input For #tag_11...
Benchmarking Hashtag fetching with input For #tag_12...
Benchmarking Hashtag fetching with input For #tag_13...
Benchmarking Hashtag fetching with input For #tag_14...
Benchmarking Hashtag fetching with input For #tag_15...
Benchmarking Hashtag fetching with input For #tag_16...
Benchmarking Hashtag fetching with input For #tag_17...
Benchmarking Hashtag fetching with input For #tag_18...
Benchmarking Hashtag fetching with input For #tag_19...
Benchmarking Hashtag fetching with input For #tag_20...

##### With input For #tag_0 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        328.11        3.05 ms     ±8.51%        3.07 ms        3.61 ms

##### With input For #tag_1 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        264.03        3.79 ms     ±7.20%        3.78 ms        4.45 ms

##### With input For #tag_2 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        207.43        4.82 ms     ±8.43%        4.83 ms        5.79 ms

##### With input For #tag_3 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        181.43        5.51 ms    ±10.58%        5.48 ms        6.93 ms

##### With input For #tag_4 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        205.36        4.87 ms     ±9.58%        4.88 ms        6.08 ms

##### With input For #tag_5 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        231.66        4.32 ms    ±10.67%        4.32 ms        5.48 ms

##### With input For #tag_6 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        256.04        3.91 ms     ±8.50%        3.90 ms        4.69 ms

##### With input For #tag_7 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        288.18        3.47 ms     ±8.35%        3.48 ms        4.14 ms

##### With input For #tag_8 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        334.52        2.99 ms     ±9.40%        3.01 ms        3.65 ms

##### With input For #tag_9 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        331.43        3.02 ms     ±7.59%        3.02 ms        3.56 ms

##### With input For #tag_10 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        332.26        3.01 ms    ±10.62%        3.03 ms        3.71 ms

##### With input For #tag_11 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        338.07        2.96 ms     ±8.43%        2.97 ms        3.54 ms

##### With input For #tag_12 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        348.38        2.87 ms     ±9.69%        2.88 ms        3.43 ms

##### With input For #tag_13 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        349.74        2.86 ms     ±7.63%        2.85 ms        3.47 ms

##### With input For #tag_14 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        356.24        2.81 ms     ±6.58%        2.80 ms        3.32 ms

##### With input For #tag_15 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        372.90        2.68 ms     ±7.40%        2.66 ms        3.23 ms

##### With input For #tag_16 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        362.35        2.76 ms     ±8.52%        2.75 ms        3.37 ms

##### With input For #tag_17 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        350.83        2.85 ms     ±7.44%        2.84 ms        3.39 ms

##### With input For #tag_18 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        358.98        2.79 ms     ±8.35%        2.79 ms        3.40 ms

##### With input For #tag_19 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        369.09        2.71 ms    ±12.16%        2.65 ms        3.53 ms

##### With input For #tag_20 #####
Name                       ips        average  deviation         median         99th %
Hashtag fetching        478.84        2.09 ms     ±7.93%        2.08 ms        2.54 ms

As you can see, performance isn't quite as good as when using named statements and force_custom_plan, so i also added some info to the installation docs for postgres 12.

Merge request reports