Build a key from a projected vbinding's value tuple (all WITH output items), * used to detect duplicate rows for WITH DISTINCT (#238). */
| 4057 | /* Build a key from a projected vbinding's value tuple (all WITH output items), |
| 4058 | * used to detect duplicate rows for WITH DISTINCT (#238). */ |
| 4059 | static void with_proj_key(cbm_return_clause_t *wc, binding_t *b, char *key, size_t key_sz) { |
| 4060 | int kl = 0; |
| 4061 | key[0] = '\0'; |
| 4062 | char name_buf[CBM_SZ_256]; |
| 4063 | for (int ci = 0; ci < wc->count; ci++) { |
| 4064 | const char *alias = resolve_item_alias(&wc->items[ci], name_buf, sizeof(name_buf)); |
| 4065 | const char *v = binding_get_virtual(b, alias, NULL); |
| 4066 | int w = snprintf(key + kl, (kl < (int)key_sz) ? key_sz - (size_t)kl : 0, "%s|", v ? v : ""); |
| 4067 | if (w > 0) { |
| 4068 | kl += w; |
| 4069 | } |
| 4070 | if (kl >= (int)key_sz) { |
| 4071 | break; /* buffer full */ |
| 4072 | } |
| 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | /* Apply WITH DISTINCT: drop projected rows whose value tuple duplicates an |
| 4077 | * earlier one, keeping first occurrence (#238 — previously silently ignored). */ |
no test coverage detected