diff --git a/pkg/sql/explain_bundle.go b/pkg/sql/explain_bundle.go index 7b7dabe49ffb..1671c723214a 100644 --- a/pkg/sql/explain_bundle.go +++ b/pkg/sql/explain_bundle.go @@ -416,11 +416,6 @@ func (b *stmtBundleBuilder) addEnv(ctx context.Context) { b.z.AddFile("env.sql", buf.String()) - if b.flags.RedactValues { - b.z.AddFile("schema.sql", "-- schema redacted\n") - return - } - mem := b.plan.mem if mem == nil { // No optimizer plans; an error must have occurred during planning. @@ -466,13 +461,13 @@ func (b *stmtBundleBuilder) addEnv(ctx context.Context) { } for i := range tables { blankLine() - if err := c.PrintCreateTable(&buf, &tables[i]); err != nil { + if err := c.PrintCreateTable(&buf, &tables[i], b.flags.RedactValues); err != nil { fmt.Fprintf(&buf, "-- error getting schema for table %s: %v\n", tables[i].String(), err) } } for i := range views { blankLine() - if err := c.PrintCreateView(&buf, &views[i]); err != nil { + if err := c.PrintCreateView(&buf, &views[i], b.flags.RedactValues); err != nil { fmt.Fprintf(&buf, "-- error getting schema for view %s: %v\n", views[i].String(), err) } } @@ -482,7 +477,8 @@ func (b *stmtBundleBuilder) addEnv(ctx context.Context) { b.z.AddFile("schema.sql", buf.String()) for i := range tables { buf.Reset() - if err := c.PrintTableStats(&buf, &tables[i], false /* hideHistograms */); err != nil { + hideHistograms := b.flags.RedactValues + if err := c.PrintTableStats(&buf, &tables[i], hideHistograms); err != nil { fmt.Fprintf(&buf, "-- error getting statistics for table %s: %v\n", tables[i].String(), err) } b.z.AddFile(fmt.Sprintf("stats-%s.sql", tables[i].String()), buf.String()) @@ -771,9 +767,15 @@ func (c *stmtEnvCollector) PrintClusterSettings(w io.Writer) error { return nil } -func (c *stmtEnvCollector) PrintCreateTable(w io.Writer, tn *tree.TableName) error { +func (c *stmtEnvCollector) PrintCreateTable( + w io.Writer, tn *tree.TableName, redactValues bool, +) error { + var formatOption string + if redactValues { + formatOption = " WITH REDACT" + } createStatement, err := c.query( - fmt.Sprintf("SELECT create_statement FROM [SHOW CREATE TABLE %s]", tn.String()), + fmt.Sprintf("SELECT create_statement FROM [SHOW CREATE TABLE %s%s]", tn.String(), formatOption), ) if err != nil { return err @@ -793,9 +795,15 @@ func (c *stmtEnvCollector) PrintCreateSequence(w io.Writer, tn *tree.TableName) return nil } -func (c *stmtEnvCollector) PrintCreateView(w io.Writer, tn *tree.TableName) error { +func (c *stmtEnvCollector) PrintCreateView( + w io.Writer, tn *tree.TableName, redactValues bool, +) error { + var formatOption string + if redactValues { + formatOption = " WITH REDACT" + } createStatement, err := c.query(fmt.Sprintf( - "SELECT create_statement FROM [SHOW CREATE VIEW %s]", tn.String(), + "SELECT create_statement FROM [SHOW CREATE VIEW %s%s]", tn.String(), formatOption, )) if err != nil { return err diff --git a/pkg/sql/explain_bundle_test.go b/pkg/sql/explain_bundle_test.go index b29ef30385fb..025267466375 100644 --- a/pkg/sql/explain_bundle_test.go +++ b/pkg/sql/explain_bundle_test.go @@ -300,7 +300,7 @@ CREATE TABLE users(id UUID DEFAULT gen_random_uuid() PRIMARY KEY, promo_id INT R } } return nil - }, "env.sql plan.txt schema.sql statement.sql vec-v.txt vec.txt", + }, "env.sql plan.txt schema.sql statement.sql stats-defaultdb.public.pterosaur.sql vec-v.txt vec.txt", ) }) } diff --git a/pkg/sql/opt_exec_factory.go b/pkg/sql/opt_exec_factory.go index 2ab30bc32fc5..9335f22d9088 100644 --- a/pkg/sql/opt_exec_factory.go +++ b/pkg/sql/opt_exec_factory.go @@ -1233,7 +1233,9 @@ func (ef *execFactory) showEnv(plan string, envOpts exec.ExplainEnvData) (exec.N // statements for tables referenced via FKs in these tables. for i := range envOpts.Tables { out.writef("") - if err := c.PrintCreateTable(&out.buf, &envOpts.Tables[i]); err != nil { + if err := c.PrintCreateTable( + &out.buf, &envOpts.Tables[i], false, /* redactValues */ + ); err != nil { return nil, err } out.writef("") @@ -1252,7 +1254,7 @@ func (ef *execFactory) showEnv(plan string, envOpts exec.ExplainEnvData) (exec.N for i := range envOpts.Views { out.writef("") - if err := c.PrintCreateView(&out.buf, &envOpts.Views[i]); err != nil { + if err := c.PrintCreateView(&out.buf, &envOpts.Views[i], false /* redactValues */); err != nil { return nil, err } }