Build a key from a projected vbinding's value tuple (all WITH output items), * used to detect duplicate rows for WITH DISTINCT (#238). */
| 3712 | /* Build a key from a projected vbinding's value tuple (all WITH output items), |
| 3713 | * used to detect duplicate rows for WITH DISTINCT (#238). */ |
| 3714 | static void with_proj_key(cbm_return_clause_t *wc, binding_t *b, char *key, size_t key_sz) { |
| 3715 | int kl = 0; |
| 3716 | key[0] = '\0'; |
| 3717 | char name_buf[CBM_SZ_256]; |
| 3718 | for (int ci = 0; ci < wc->count; ci++) { |
| 3719 | const char *alias = resolve_item_alias(&wc->items[ci], name_buf, sizeof(name_buf)); |
| 3720 | const char *v = binding_get_virtual(b, alias, NULL); |
| 3721 | int w = snprintf(key + kl, (kl < (int)key_sz) ? key_sz - (size_t)kl : 0, "%s|", v ? v : ""); |
| 3722 | if (w > 0) { |
| 3723 | kl += w; |
| 3724 | } |
| 3725 | if (kl >= (int)key_sz) { |
| 3726 | break; /* buffer full */ |
| 3727 | } |
| 3728 | } |
| 3729 | } |
| 3730 | |
| 3731 | /* Apply WITH DISTINCT: drop projected rows whose value tuple duplicates an |
| 3732 | * earlier one, keeping first occurrence (#238 — previously silently ignored). */ |
no test coverage detected