-
Notifications
You must be signed in to change notification settings - Fork 12
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
pg: advanced query feats, table inspection, and stats #901
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package sql | ||
|
||
// NOTE: this file is TRANSITIONAL! These types are lifted from the | ||
// unmerged internal/engine/costs/datatypes package. | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// Statistics contains statistics about a table or a Plan. A Statistics can be | ||
// derived directly from the underlying table, or derived from the statistics of | ||
// its children. | ||
type Statistics struct { | ||
RowCount int64 | ||
|
||
ColumnStatistics []ColumnStatistics | ||
|
||
//Selectivity, for plan statistics | ||
} | ||
|
||
func (s *Statistics) String() string { | ||
var st strings.Builder | ||
fmt.Fprintf(&st, "RowCount: %d", s.RowCount) | ||
if len(s.ColumnStatistics) > 0 { | ||
fmt.Fprintln(&st, "") | ||
} | ||
for i, cs := range s.ColumnStatistics { | ||
fmt.Fprintf(&st, " Column %d:\n", i) | ||
fmt.Fprintf(&st, " - Min/Max = %v / %v\n", cs.Min, cs.Max) | ||
fmt.Fprintf(&st, " - NULL count = %v\n", cs.NullCount) | ||
} | ||
return st.String() | ||
} | ||
|
||
type ValCount struct { | ||
Val any | ||
Count int | ||
} | ||
|
||
// ColumnStatistics contains statistics about a column. | ||
type ColumnStatistics struct { | ||
NullCount int64 | ||
|
||
Min any | ||
MinCount int | ||
|
||
Max any | ||
MaxCount int | ||
|
||
// MCVs are the most common values. It should be sorted by the value. It | ||
// should also be limited capacity, which means scan order has to be | ||
// deterministic since we have to throw out same-frequency observations. | ||
// (crap) Solution: multi-pass scan, merge lists, continue until no higher | ||
// freq values observed? OR when capacity reached, use a histogram? Do not | ||
// throw away MCVs, just start putting additional observations in to the | ||
// histogram instead. | ||
// MCVs []ValCount | ||
// MCVs map[cmp.Ordered] | ||
|
||
// MCVals []any | ||
// MCFreqs []int | ||
|
||
// DistinctCount is harder. For example, unless we sub-sample | ||
// (deterministically), tracking distinct values could involve a data | ||
// structure with the same number of elements as rows in the table. | ||
DistinctCount int64 | ||
|
||
AvgSize int64 // maybe: length of text, length of array, otherwise not used for scalar? | ||
|
||
// without histogram, we can make uniformity assumption to simplify the cost model | ||
//Histogram []HistogramBucket | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall seems find, but what is the reason for not doing something more conventional, similar to the standard library's
sql.Rows
(containingNext()
,Scan()
, etc.)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically just no real reason to introduce a rows type. The for each helpers in the pgx package were also a more intuitive building block for this method.