This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "crypto/rand" | |
| "database/sql" | |
| _ "github.com/lib/pq" | |
| "time" | |
| ) | |
| const ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/hex" | |
| "fmt" | |
| "github.com/rueian/pgbroker/backend" | |
| "github.com/rueian/pgbroker/message" | |
| "github.com/rueian/pgbroker/proxy" | |
| "net" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| postgres=# explain analyze select * from counters where id like 'ms:149895:%'; | |
| QUERY PLAN | |
| --------------------------------------------------------------------------------------------------------------------------- | |
| Index Scan using counters_pkey on counters (cost=0.56..8.58 rows=49 width=36) (actual time=0.015..0.023 rows=10 loops=1) | |
| Index Cond: ((id >= 'ms:149895:'::text) AND (id < 'ms:149895;'::text)) | |
| Filter: (id ~~ 'ms:149895:%'::text) | |
| Planning Time: 0.146 ms | |
| Execution Time: 0.036 ms | |
| (5 rows) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* In any case, don't believe extremely small or large estimates. */ | |
| if (selec < 0.00001) | |
| selec = 0.00001; | |
| else if (selec > 0.9999) | |
| selec = 0.9999; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| else if (IsA(rawreq, SupportRequestIndexCondition)) | |
| { | |
| /* Try to convert operator/function call to index conditions */ | |
| SupportRequestIndexCondition *req = (SupportRequestIndexCondition *) rawreq; | |
| /* | |
| * Currently we have no "reverse" match operators with the pattern on | |
| * the left, so we only need consider cases with the indexkey on the | |
| * left. | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| postgres=# explain analyze select * from counters where id >= 'ms:149895:' and id <= 'ms:149895;' and id like 'ms:149895:%'; | |
| QUERY PLAN | |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
| Index Scan using counters_pkey on counters (cost=0.56..8.58 rows=1 width=36) (actual time=0.023..0.039 rows=10 loops=1) | |
| Index Cond: ((id >= 'ms:149895:'::text) AND (id <= 'ms:149895;'::text) AND (id >= 'ms:149895:'::text) AND (id < 'ms:149895;'::text)) | |
| Filter: (id ~~ 'ms:149895:%'::text) | |
| Planning Time: 0.156 ms | |
| Execution Time: 0.036 ms | |
| (5 rows) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| postgres=# EXPLAIN SELECT * FROM counters; | |
| QUERY PLAN | |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
| Seq Scan on counters (cost=0.00..89169.11 rows=4880311 width=36) | |
| (1 row) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| postgres=# SELECT unnest(histogram_bounds::text::text[]) FROM pg_stats WHERE tablename='counters' AND attname='id'; | |
| unnest | |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
| ms:103734:p | |
| ms:1074631:cl | |
| ms:1103301:c | |
| ms:1137423:pn | |
| ms:1168158:pr | |
| ms:1192862:p | |
| ms:1221019:cl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| postgres=# SELECT array_length(histogram_bounds, 1) FROM pg_stats WHERE tablename='counters' AND attname='id'; | |
| array_length | |
| - - - - - - - | |
| 101 | |
| (1 row) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * If we have most-common-values info, add up the fractions of the MCV | |
| * entries that satisfy MCV OP PATTERN. These fractions contribute | |
| * directly to the result selectivity. Also add up the total fraction | |
| * represented by MCV entries. | |
| */ | |
| mcv_selec = mcv_selectivity(&vardata, &opproc, constval, true, | |
| &sumcommon); | |
| /* |