Skip to content

x/sqlbuilder: Implement MultiColumnIn#45

Open
AlexisMontagne wants to merge 1 commit intomasterfrom
am/multi-clause-in
Open

x/sqlbuilder: Implement MultiColumnIn#45
AlexisMontagne wants to merge 1 commit intomasterfrom
am/multi-clause-in

Conversation

@AlexisMontagne
Copy link
Member

@AlexisMontagne AlexisMontagne commented Mar 25, 2026

What does this PR do?

In our internal code base we have a lot of queries that look like:

SELECT bar FROM foo WHERE (a = $1 AND b = $2) OR (a = $3 AND b = $4)

For our current version of postgres it suffers from pretty poor performances.

This new predicate clause, should make it easy to write query like:

SELECT bar FROM foo WHERE (a, b) IN (($1, $2), ($3, $4))

What are the observable changes?

Good PR checklist

  • Title makes sense
  • Is against the correct branch
  • Only addresses one issue
  • Properly assigned
  • Added/updated tests
  • Added/updated documentation
  • Properly labeled

Additional Notes

@AlexisMontagne AlexisMontagne self-assigned this Mar 25, 2026
@AlexisMontagne AlexisMontagne requested a review from a team as a code owner March 25, 2026 00:32
@AlexisMontagne AlexisMontagne requested review from FlorianRichardUPF and xgoffin and removed request for a team March 25, 2026 00:32

func (mc *multiColumnInClause) WriteTo(w QueryWriter, vs map[string]interface{}) error {
if _, ok := vs[mc.k]; !ok || len(mc.ms) == 0 {
io.WriteString(w, "1=0")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Error return value of io.WriteString is not checked (errcheck)

return ErrMissingKey{b}
}

io.WriteString(w, w.RedeemVariable(vv.Interface()))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Error return value of io.WriteString is not checked (errcheck)

io.WriteString(w, w.RedeemVariable(vv.Interface()))

if j < len(bindings)-1 {
io.WriteString(w, ", ")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Error return value of io.WriteString is not checked (errcheck)

}

if v.Len() == 0 {
io.WriteString(w, "1=0")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Error return value of io.WriteString is not checked (errcheck)

}

if i < v.Len()-1 {
io.WriteString(w, ", ")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Error return value of io.WriteString is not checked (errcheck)

func (mc *multiColumnInClause) WriteTo(w QueryWriter, vs map[string]interface{}) error {
if _, ok := vs[mc.k]; !ok || len(mc.ms) == 0 {
io.WriteString(w, "1=0")
return nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
return with no blank line before (nlreturn)

}

fmt.Fprint(w, ")")
return nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
return with no blank line before (nlreturn)


if v.Len() == 0 {
io.WriteString(w, "1=0")
return nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
return with no blank line before (nlreturn)

}

io.WriteString(w, ")")
return nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
return with no blank line before (nlreturn)

func writeInClause(w QueryWriter, vv interface{}, k string) error {
return writeInValues(w, vv, k, func(w QueryWriter, elem interface{}) error {
io.WriteString(w, w.RedeemVariable(elem))
return nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
return with no blank line before (nlreturn)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants