@@ -1232,20 +1232,32 @@ TUniqueConstraintNodeBase<Distinct>::DoGetSimplifiedForType(const TTypeAnnotatio
12321232 for (bool setChanged = true ; setChanged;) {
12331233 setChanged = false ;
12341234 for (auto it = sets.begin (); sets.end () != it;) {
1235- if (it->size () != 1U || it->front ().size () <= 1U )
1236- ++it;
1237- else {
1235+ if (!it->empty () && it->front ().size () > 1U ) {
1236+ TPartOfConstraintBase::TSetType prefixes;
1237+ prefixes.reserve (it->size ());
1238+ for (const auto & path : *it) {
1239+ if (path.size () > 1U ) {
1240+ prefixes.emplace_back (getPrefix (path));
1241+ }
1242+ }
1243+
12381244 auto from = it++;
1239- const auto prefix = getPrefix (from->front ());
1240- while (sets.cend () != it && it->size () == 1U && it->front ().size () > 1U && prefix == getPrefix (it->front ()))
1241- ++it;
1245+ if (prefixes.size () < from->size ())
1246+ continue ;
12421247
1243- if (ssize_t (GetElementsCount (TBase::GetSubTypeByPath (prefix, rowType))) == std::distance (from, it)) {
1244- *from++ = TPartOfConstraintBase::TSetType{std::move (prefix)};
1248+ while (sets.cend () != it && it->size () == prefixes.size () &&
1249+ std::all_of (it->cbegin (), it->cend (), [&](const TPartOfConstraintBase::TPathType& path) { return path.size () > 1U && prefixes.contains (getPrefix (path)); })) {
1250+ ++it;
1251+ }
1252+
1253+ if (std::all_of (prefixes.cbegin (), prefixes.cend (),
1254+ [width = std::distance (from, it), &rowType] (const TPartOfConstraintBase::TPathType& path) { return width == ssize_t (GetElementsCount (TBase::GetSubTypeByPath (path, rowType))); })) {
1255+ *from++ =std::move (prefixes);
12451256 it = sets.erase (from, it);
12461257 changed = setChanged = true ;
12471258 }
1248- }
1259+ } else
1260+ ++it;
12491261 }
12501262 }
12511263 }
0 commit comments