-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema_test.go
199 lines (188 loc) · 6.67 KB
/
schema_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package db
import (
"database/sql"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTableDelta(t *testing.T) {
p := &Table{
Name: "table",
Schema: "schema",
TotalBytes: 1000,
TotalBytesTotal: 2000,
IndexBytes: 500,
IndexBytesTotal: 5000,
ToastBytes: 1000,
ToastBytesTotal: 1000,
TableBytes: 1000,
TableBytesTotal: 1000,
BloatBytes: 1000,
BloatBytesTotal: 1000,
BloatFactor: 0.2,
SequentialScans: 10000,
SequentialScanReadRows: 10000,
IndexScans: 10000,
IndexScanReadRows: 10000,
InsertedRows: 10000,
UpdatedRows: 10000,
DeletedRows: 10000,
LiveRowEstimate: 10000,
LiveRowEstimateTotal: 10000,
DeadRowEstimate: 10000,
DeadRowEstimateTotal: 10000,
ModifiedRowsSinceAnalyze: 10000,
LastVacuumAt: sql.NullInt64{Valid: true, Int64: 1000},
LastAutovacuumAt: sql.NullInt64{Valid: true, Int64: 1000},
LastAnalyzeAt: sql.NullInt64{Valid: true, Int64: 1000},
LastAutoanalyzeAt: sql.NullInt64{Valid: true, Int64: 1000},
VacuumCount: 10000,
AutovacuumCount: 10000,
AnalyzeCount: 10000,
AutoanalyzeCount: 10000,
DiskBlocksRead: 10000,
DiskBlocksHit: 10000,
DiskIndexBlocksRead: 10000,
DiskIndexBlocksHit: 10000,
DiskToastBlocksRead: 10000,
DiskToastBlocksHit: 10000,
DiskToastIndexBlocksRead: 10000,
DiskToastIndexBlocksHit: 10000,
}
l := &Table{
Name: "table",
Schema: "schema",
TotalBytes: 1000,
TotalBytesTotal: 3000,
IndexBytes: 500,
IndexBytesTotal: 6000,
ToastBytes: 1000,
ToastBytesTotal: 2000,
TableBytes: 1000,
TableBytesTotal: 2000,
BloatBytes: 1000,
BloatBytesTotal: 2000,
BloatFactor: 0.2,
SequentialScans: 10000,
SequentialScanReadRows: 10000,
IndexScans: 10000,
IndexScanReadRows: 10000,
InsertedRows: 10000,
UpdatedRows: 10000,
DeletedRows: 10000,
LiveRowEstimate: 10000,
LiveRowEstimateTotal: 20000,
DeadRowEstimate: 10000,
DeadRowEstimateTotal: 20000,
ModifiedRowsSinceAnalyze: 10000,
LastVacuumAt: sql.NullInt64{Valid: true, Int64: 1000},
LastAutovacuumAt: sql.NullInt64{Valid: true, Int64: 1000},
LastAnalyzeAt: sql.NullInt64{Valid: true, Int64: 1000},
LastAutoanalyzeAt: sql.NullInt64{Valid: true, Int64: 1000},
VacuumCount: 10000,
AutovacuumCount: 10000,
AnalyzeCount: 10000,
AutoanalyzeCount: 10000,
DiskBlocksRead: 10000,
DiskBlocksHit: 10000,
DiskIndexBlocksRead: 10000,
DiskIndexBlocksHit: 10000,
DiskToastBlocksRead: 10000,
DiskToastBlocksHit: 10000,
DiskToastIndexBlocksRead: 10000,
DiskToastIndexBlocksHit: 10000,
}
d := p.Delta(l)
assert.Equal(t, "table", d.Name)
assert.Equal(t, "schema", d.Schema)
assert.Equal(t, int64(1000), d.TotalBytes)
assert.Equal(t, int64(3000), d.TotalBytesTotal)
assert.Equal(t, int64(1000), d.IndexBytes)
assert.Equal(t, int64(6000), d.IndexBytesTotal)
assert.Equal(t, int64(1000), d.ToastBytes)
assert.Equal(t, int64(2000), d.ToastBytesTotal)
assert.Equal(t, int64(1000), d.TableBytes)
assert.Equal(t, int64(2000), d.TableBytesTotal)
assert.Equal(t, int64(1000), d.BloatBytes)
assert.Equal(t, int64(2000), d.BloatBytesTotal)
assert.Equal(t, float64(0.2), d.BloatFactor)
assert.Equal(t, int64(0), d.SequentialScans)
assert.Equal(t, int64(0), d.SequentialScanReadRows)
assert.Equal(t, int64(0), d.IndexScans)
assert.Equal(t, int64(0), d.IndexScanReadRows)
assert.Equal(t, int64(0), d.InsertedRows)
assert.Equal(t, int64(0), d.UpdatedRows)
assert.Equal(t, int64(0), d.DeletedRows)
assert.Equal(t, int64(10000), d.LiveRowEstimate)
assert.Equal(t, int64(20000), d.LiveRowEstimateTotal)
assert.Equal(t, int64(10000), d.DeadRowEstimate)
assert.Equal(t, int64(20000), d.DeadRowEstimateTotal)
assert.Equal(t, int64(10000), d.ModifiedRowsSinceAnalyze)
assert.Equal(t, sql.NullInt64{Valid: true, Int64: 1000}, d.LastVacuumAt)
assert.Equal(t, sql.NullInt64{Valid: true, Int64: 1000}, d.LastAutovacuumAt)
assert.Equal(t, sql.NullInt64{Valid: true, Int64: 1000}, d.LastAnalyzeAt)
assert.Equal(t, sql.NullInt64{Valid: true, Int64: 1000}, d.LastAutoanalyzeAt)
assert.Equal(t, int64(0), d.VacuumCount)
assert.Equal(t, int64(0), d.AutovacuumCount)
assert.Equal(t, int64(0), d.AnalyzeCount)
assert.Equal(t, int64(0), d.AutoanalyzeCount)
assert.Equal(t, int64(0), d.DiskBlocksRead)
assert.Equal(t, int64(0), d.DiskBlocksHit)
assert.Equal(t, int64(0), d.DiskIndexBlocksRead)
assert.Equal(t, int64(0), d.DiskIndexBlocksHit)
assert.Equal(t, int64(0), d.DiskToastBlocksRead)
assert.Equal(t, int64(0), d.DiskToastBlocksHit)
assert.Equal(t, int64(0), d.DiskToastIndexBlocksRead)
assert.Equal(t, int64(0), d.DiskToastIndexBlocksHit)
}
func TestIndexDelta(t *testing.T) {
i := &Index{
Name: "index",
Schema: "schema",
TableName: "table",
Unique: true,
Unused: false,
Valid: true,
Definition: "definition",
Bytes: 0,
BytesTotal: 1000,
BloatBytes: 200,
BloatBytesTotal: 200,
BloatFactor: 0.2,
Scans: 10000,
DiskBlocksRead: 5,
DiskBlocksHit: 10,
}
l := &Index{
Name: "index",
Schema: "schema",
TableName: "table",
Unique: false,
Unused: true,
Valid: false,
Definition: "definition2",
Bytes: 0,
BytesTotal: 2000,
BloatBytes: 200,
BloatBytesTotal: 300,
BloatFactor: 0.3,
Scans: 40000,
DiskBlocksRead: 6,
DiskBlocksHit: 100,
}
d := i.Delta(l)
assert.Equal(t, "index", d.Name)
assert.Equal(t, "schema", d.Schema)
assert.Equal(t, "table", d.TableName)
assert.Equal(t, false, d.Unique)
assert.Equal(t, true, d.Unused)
assert.Equal(t, false, d.Valid)
assert.Equal(t, "definition2", d.Definition)
assert.Equal(t, int64(1000), d.Bytes)
assert.Equal(t, int64(2000), d.BytesTotal)
assert.Equal(t, int64(100), d.BloatBytes)
assert.Equal(t, int64(300), d.BloatBytesTotal)
assert.Equal(t, float64(0.3), d.BloatFactor)
assert.Equal(t, int64(30000), d.Scans)
assert.Equal(t, int64(1), d.DiskBlocksRead)
assert.Equal(t, int64(90), d.DiskBlocksHit)
}