@@ -8,8 +8,6 @@ package sql
88import (
99 "context"
1010 "fmt"
11- "os"
12- "path/filepath"
1311 "regexp"
1412 "strconv"
1513 "strings"
@@ -19,7 +17,6 @@ import (
1917 "github.com/cockroachdb/cockroach/pkg/base"
2018 "github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
2119 "github.com/cockroachdb/cockroach/pkg/testutils"
22- "github.com/cockroachdb/cockroach/pkg/testutils/datapathutils"
2320 "github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
2421 "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
2522 "github.com/cockroachdb/cockroach/pkg/util/leaktest"
@@ -159,7 +156,6 @@ func TestStreamerTightBudget(t *testing.T) {
159156 // Streamer isn't hitting the root budget exceeded error.
160157 s , db , _ := serverutils .StartServer (t , base.TestServerArgs {
161158 SQLMemoryPoolSize : 1 << 30 , /* 1GiB */
162- Insecure : true ,
163159 })
164160 defer s .Stopper ().Stop (context .Background ())
165161 sqlDB := sqlutils .MakeSQLRunner (db )
@@ -184,9 +180,9 @@ func TestStreamerTightBudget(t *testing.T) {
184180 sqlDB .Exec (t , fmt .Sprintf ("SET distsql_workmem = '%dB'" , blobSize ))
185181
186182 // Perform an index join to read the blobs.
187- query := "SELECT sum(length(blob)) FROM t@t_k_idx WHERE k = 1"
183+ query := "EXPLAIN ANALYZE SELECT sum(length(blob)) FROM t@t_k_idx WHERE k = 1"
188184 maximumMemoryUsageRegex := regexp .MustCompile (`maximum memory usage: (\d+\.\d+) MiB` )
189- rows := sqlDB .QueryStr (t , "EXPLAIN ANALYZE (VERBOSE) " + query )
185+ rows := sqlDB .QueryStr (t , query )
190186 // Build pretty output for an error message in case we need it.
191187 var sb strings.Builder
192188 for _ , row := range rows {
@@ -201,45 +197,9 @@ func TestStreamerTightBudget(t *testing.T) {
201197 // by the ColIndexJoin when the blob is copied into the columnar
202198 // batch). We allow for 0.1MiB for other memory usage in the query.
203199 maxAllowed := 2.1
204- if maxAllowed >= usage {
205- return
206- }
207- // Get a stmt bundle for this query that might help in debugging the
208- // failure.
209- rows = sqlDB .QueryStr (t , "EXPLAIN ANALYZE (DEBUG) " + query )
210- url := getBundleDownloadURL (t , fmt .Sprint (rows ))
211- // First check whether the bundle experienced the elevated memory
212- // usage too.
213- unzip := downloadAndUnzipBundle (t , url )
214- for _ , f := range unzip .File {
215- switch f .Name {
216- case "plan.txt" :
217- contents := readUnzippedFile (t , f )
218- sb .WriteString ("\n \n \n bundle plan.txt:\n \n \n " )
219- sb .WriteString (contents )
220- // Check that the memory usage is still elevated.
221- if matches := maximumMemoryUsageRegex .FindStringSubmatch (contents ); len (matches ) == 0 {
222- t .Fatalf ("unexpectedly didn't find a match for maximum memory usage\n %s" , sb .String ())
223- } else {
224- bundleUsage , err := strconv .ParseFloat (matches [1 ], 64 )
225- require .NoError (t , err )
226- if maxAllowed >= bundleUsage {
227- // Memory usage is as expected in the bundle - do
228- // not fail the test since we don't have any
229- // information to help in understanding the original
230- // high memory usage.
231- return
232- }
233- }
234- }
235- }
236- // NB: we're not using t.TempDir() because we want these to survive
237- // on failure.
238- f , err := os .Create (filepath .Join (datapathutils .DebuggableTempDir (), "bundle.zip" ))
239- require .NoError (t , err )
240- downloadBundle (t , url , f )
241- t .Fatalf ("unexpectedly high memory usage\n ----\n %s" , sb .String ())
200+ require .GreaterOrEqualf (t , maxAllowed , usage , "unexpectedly high memory usage\n ----\n %s" , sb .String ())
201+ return
242202 }
243203 }
244- t .Fatalf ("unexpectedly didn't find a match for maximum memory usage\n %s" , sb . String () )
204+ t .Fatal ("unexpectedly didn't find a match for maximum memory usage" )
245205}
0 commit comments