expandArgs expands any named args that are slices into multiple named args, one for each element in the slice. This is useful for queries that use the IN operator, e.g. SELECT * FROM table WHERE id IN (:id)
- If there are no args, the original stmt and args are returned.
- If there are no slices to expand, the original stmt and args are returned.
- If the args are positional, the original stmt and args are returned, as we can't expand positional args.
- Only slices of primitives are supported. Slices of structs or other types are not supported.
- Stmts are not supported, as the stmt string can't be modified after Prepare is called
Benchmarked 2024-05-09 on an M3 Max Macbook Pro 2023, 16-inch, 36GB RAM, macOS 14.4.1, Go 1.22.3
goos: darwin
goarch: arm64
pkg: go.nozzle.io/pkg/mysql
Benchmark_expandArgs
Benchmark_expandArgs/no_args
Benchmark_expandArgs/no_args-14 857257668 1.386 ns/op 0 B/op 0 allocs/op
Benchmark_expandArgs/positional:_no_array_arg,_1_arg
Benchmark_expandArgs/positional:_no_array_arg,_1_arg-14 566456900 2.110 ns/op 0 B/op 0 allocs/op
Benchmark_expandArgs/positional:_no_array_arg,_1,000_ints
Benchmark_expandArgs/positional:_no_array_arg,_1,000_ints-14 570863935 2.113 ns/op 0 B/op 0 allocs/op
Benchmark_expandArgs/positional:_no_array_arg,_1,000_strings
Benchmark_expandArgs/positional:_no_array_arg,_1,000_strings-14 564158204 2.142 ns/op 0 B/op 0 allocs/op
Benchmark_expandArgs/positional:_no_array_arg,_100,000_ints
Benchmark_expandArgs/positional:_no_array_arg,_100,000_ints-14 563225262 2.116 ns/op 0 B/op 0 allocs/op
Benchmark_expandArgs/positional:_no_array_arg,_100,000_strings
Benchmark_expandArgs/positional:_no_array_arg,_100,000_strings-14 563380719 2.115 ns/op 0 B/op 0 allocs/op
Benchmark_expandArgs/named:_no_array_arg
Benchmark_expandArgs/named:_no_array_arg-14 230793308 5.211 ns/op 0 B/op 0 allocs/op
Benchmark_expandArgs/named:_one_array_arg_with_3_elements
Benchmark_expandArgs/named:_one_array_arg_with_3_elements-14 250725536 4.831 ns/op 0 B/op 0 allocs/op
Benchmark_expandArgs/named:_one_array_arg_with_1,000_elements
Benchmark_expandArgs/named:_one_array_arg_with_1,000_elements-14 248725476 4.808 ns/op 0 B/op 0 allocs/op
Benchmark_expandArgs/named:_one_array_arg_with_100,000_elements
Benchmark_expandArgs/named:_one_array_arg_with_100,000_elements-14 245566166 5.083 ns/op 0 B/op 0 allocs/op
Benchmark_expandArgs/named:_one_array_arg_with_3_elements_and_one_normal_arg
Benchmark_expandArgs/named:_one_array_arg_with_3_elements_and_one_normal_arg-14 171625336 7.009 ns/op 0 B/op 0 allocs/op
Benchmark_expandArgs/named:_one_array_arg_with_100,000_elements_and_one_normal_arg
Benchmark_expandArgs/named:_one_array_arg_with_100,000_elements_and_one_normal_arg-14 172396051 6.967 ns/op 0 B/op 0 allocs/op