Commit aab4263
authored
perf(substr_index): speed up scalar and Utf8View (#21754)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Part of #20585.
## Rationale for this change
`substr_index` is part of the Utf8View epic. This function was still
missing the Utf8View optimization path, and it also did extra work when
delimiter and count were constant scalars.
This PR adds the same kind of optimization used in similar string work
and includes benchmark coverage.
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
- Return the input string type directly, including `Utf8View`.
- Add a zero-copy `Utf8View` path for `substr_index`.
- Add a scalar fast path when delimiter and count are constant.
- Keep the hot path specialized after checking a cleaner shared-helper
version and benchmarking it.
- Add SQL coverage for `Utf8View` type and value results.
- Add unit tests for the scalar fast path, sliced `Utf8View` arrays, and
the unchanged original-view case.
- Extend the benchmark to cover `Utf8`, `Utf8View`, array arguments,
scalar delimiter/count, and positive and negative counts.
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
## Are these changes tested?
Yes
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
## Are there any user-facing changes?
No
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->1 parent 89e14f1 commit aab4263
3 files changed
Lines changed: 749 additions & 136 deletions
File tree
- datafusion
- functions
- benches
- src/unicode
- sqllogictest/test_files/string
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
| |||
48 | 53 | | |
49 | 54 | | |
50 | 55 | | |
51 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
52 | 105 | | |
53 | 106 | | |
54 | | - | |
55 | | - | |
56 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
57 | 110 | | |
58 | 111 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
63 | 116 | | |
64 | 117 | | |
65 | 118 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 119 | + | |
71 | 120 | | |
72 | | - | |
| 121 | + | |
73 | 122 | | |
74 | 123 | | |
75 | 124 | | |
| |||
80 | 129 | | |
81 | 130 | | |
82 | 131 | | |
83 | | - | |
84 | 132 | | |
85 | 133 | | |
86 | 134 | | |
| |||
90 | 138 | | |
91 | 139 | | |
92 | 140 | | |
93 | | - | |
94 | | - | |
95 | 141 | | |
96 | 142 | | |
97 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
98 | 161 | | |
99 | 162 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 163 | + | |
105 | 164 | | |
106 | 165 | | |
107 | 166 | | |
108 | 167 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
113 | 171 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | 172 | | |
120 | 173 | | |
121 | 174 | | |
| |||
129 | 182 | | |
130 | 183 | | |
131 | 184 | | |
132 | | - | |
| 185 | + | |
133 | 186 | | |
134 | | - | |
135 | | - | |
| 187 | + | |
| 188 | + | |
136 | 189 | | |
137 | 190 | | |
138 | 191 | | |
| |||
142 | 195 | | |
143 | 196 | | |
144 | 197 | | |
145 | | - | |
146 | 198 | | |
147 | 199 | | |
148 | 200 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
161 | 254 | | |
162 | 255 | | |
163 | 256 | | |
| |||
0 commit comments