From 1641021ad083bb2c73ccffff457a9694bb05dd68 Mon Sep 17 00:00:00 2001 From: Marcus Gartner Date: Fri, 2 Jul 2021 15:04:03 -0700 Subject: [PATCH] sqlsmith: make TLP predicates immutable Previously, `GenerateTLP` could generate predicates that were not immutable. For example, a predicate could include `random()`. The TLP method only works correctly if predicates are immutable. A non-immutable predicate can cause TLP to erroneously report a correctness bug. Release note: None --- pkg/internal/sqlsmith/tlp.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/internal/sqlsmith/tlp.go b/pkg/internal/sqlsmith/tlp.go index 07d836357feb..54b2606d38a5 100644 --- a/pkg/internal/sqlsmith/tlp.go +++ b/pkg/internal/sqlsmith/tlp.go @@ -53,6 +53,13 @@ import ( // If the resulting counts of the two queries are not equal, there is a logical // bug. func (s *Smither) GenerateTLP() (unpartitioned, partitioned string) { + // Set disableImpureFns to true so that generated predicates are immutable. + originalDisableImpureFns := s.disableImpureFns + s.disableImpureFns = true + defer func() { + s.disableImpureFns = originalDisableImpureFns + }() + f := tree.NewFmtCtx(tree.FmtParsable) table, _, _, cols, ok := s.getSchemaTable()