Skip to content

Remove unique constraints, because we have xsd:key - #998

Merged
TuThoThai merged 17 commits into
v2.0from
v2_remove_unique
Nov 17, 2026
Merged

TuThoThai merged 17 commits into
v2.0from
v2_remove_unique

Conversation

@skinkie

@skinkie skinkie commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Fix #994

With unique constraints:

real	4m5.527s
user	3m57.850s
sys	0m1.706s

Without unique constraints:

real	2m44.075s
user	2m39.062s
sys	0m1.093s

@skinkie skinkie self-assigned this Feb 26, 2026
@skinkie skinkie added the hygiene Technical dept, results in a breaking change. label Feb 26, 2026
@TuThoThai TuThoThai modified the milestones: netex_2.0, netex_2.1 Feb 26, 2026
@ue71603
ue71603 requested a review from trurlurl February 26, 2026 14:43
ue71603
ue71603 previously approved these changes Feb 26, 2026
trurlurl
trurlurl previously approved these changes Feb 27, 2026
@TuThoThai

Copy link
Copy Markdown
Contributor

@skinkie,
Considering it is not a bug fix, only a redundance, would you prefer to it to be release with 2.0.1 or 2.1? In the latter case, we only change the target branch.
🙏

@skinkie

skinkie commented Mar 7, 2026

Copy link
Copy Markdown
Contributor Author

2.0.1

@TuThoThai TuThoThai modified the milestones: netex_2.1, netex_2.0 Mar 7, 2026
@thbar

thbar commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

I had a first look locally today; the branch is not up-to-date anymore, so I'll push the "update from v2.0" from my machine. @TuThoThai in order for GitHub to detect that a branch is not up-to-date, we'll have to (re?)-enable "check status updates" first.

For both files:
* adding in the metadata the changes made most recently on ref / key constraints
* changing status from 1.0 to 2.0
@TuThoThai
TuThoThai dismissed stale reviews from ue71603 and trurlurl via 7a32074 March 8, 2026 15:05
@TuThoThai

Copy link
Copy Markdown
Contributor

@skinkie, great work on this one! It definitly helped a lot with the validation speed, but also made the Schema much faster to load with tools like XMLSpy

I made a tiny commit to:

  • add your work on ref / constraints in the metadata
  • changed the status to 2.0

TuThoThai
TuThoThai previously approved these changes Mar 8, 2026
TuThoThai
TuThoThai previously approved these changes Mar 8, 2026

@thbar thbar left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did manual + automated (AI) reviews. The vast majority (> 97%) of the stuff seems right to me. I have questions on a few remaining cases.

Can someone with more historical or functional context comment on these? (@skinkie and others!).

Unsure at this point if these are false positives / issues with the review, or something that deserves actual changes possibly.

Potentially (???) missing xsd:key Replacements

  • AlternativeName_UniqueBy_Id_Version_useForLanguage_ordered - Alternative names with language/order constraint
  • AlternativeText_UniqueBy_Id_AttributeName_UseForLanguage_Version - Alternative text with 4-field uniqueness (@id, @attributeName, @useForLanguage, @version)
  • Vehicle_UniqueRegistrationNumber - Vehicle registration number uniqueness constraint
  • Call_UniqueBy_Id_Version_Order - Call element uniqueness with ordering
  • DynamicDistanceMatrixElement_UniqueBy_Id_Version - Dynamic distance matrix element constraint

@thbar

thbar commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@thbar The should fail is not working properly.

@ue71603 they are catching that unique constraints have been removed here compared to v2.0 (but should be brought back before merging).

@TuThoThai will provide more explanations (this stuff is a bit mind-boggling due to the double negation, we did a zoom call together so she could see the trouble).

@ue71603

ue71603 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

@thbar @TuThoThai Who will do something here or in a PR that we need to undo what was done?

@ue71603

ue71603 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

@TuThoThai I am not sure which open question need to be addressed and by who:
Thanks for your reply. FR did a review on the PR #998 and there are a couple of open questions for attributes that do not have keys, so unique constraints must be rolled back. It was pending another review / rework by CH, NL and FR. But, let’s talk this through during the merge fest.

@TuThoThai

Copy link
Copy Markdown
Contributor

Based on the addition of "should-fail" examples by @thbar via #1074, it seems that there should be a roll-back on the removing of the following unique constraints as they do no have keys:

  • GroupOfLinkSequences
  • ValidBetween
  • ValidityPeriod

The roll-back could be done by any contributor directly on this PR.

I also advocate for all to review carefully once more the PR as we could have all missed other unique constraints that did not have keys. Since there are a lot of them, and at least 7 roll-backs were identified, we should handle the results of the script with care.

cc @ue71603, @skinkie, @Aurige

@skinkie

skinkie commented Oct 28, 2026 via email

Copy link
Copy Markdown
Contributor Author

@TuThoThai

Copy link
Copy Markdown
Contributor

What is the reason you want to give them a unique but not fix it to have a key?

Mostly because they didn't have a key in v1.3.2 nor in v2.0.0. So, to ensure that v2.0.1 is a patched / fixed version of v2.0.0 without any actual addition. If it makes sense.

And leave all the constraints full rework split between v2.1 and v3.0

@skinkie

skinkie commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

We had a unique, FR complained, hence it was effectively a key. So no, it does not make sense.

@TuThoThai

TuThoThai commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

We had a unique, FR complained, hence it was effectively a key. So no, it does not make sense.

Let's not rewrite history here.

In #994:

  • @Aurige suggested that when we have both unique and keys check, we remove unique in favor of keys
  • @skinkie suggested that "should-fail examples" are to be created to ensure no mistake is done

Since then,

During the review of this PR, we collectively spotted removal of unique without the existence of keys. So, I believe all that is needed is to revert back on these removal. Then, we are good to go.

@skinkie

skinkie commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

No we shouldn't revert back to unique, we should assign keys which give all the functionality of unique and is the correct solution.

@TuThoThai

Copy link
Copy Markdown
Contributor

Then, it is no longer a simple cleanup of redundancy and the PR should be targeting branch v2.1-wip

@thbar thbar mentioned this pull request Nov 16, 2026
@ue71603

ue71603 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

@thbar @TuThoThai @skinkie @Aurige can we merge this one and have the discussion as an issue for discussion in 3.0 or 2.1? The biggest part is undisputed, isn't it?

@TuThoThai

Copy link
Copy Markdown
Contributor

@ue71603, the main question before merging is what we do with these 3:

  • GroupOfLinkSequences
  • ValidBetween
  • ValidityPeriod

Option 1: simple roll back of the deletion of unique (in favor: @thbar and @TuThoThai; against: @skinkie)
Option 2: change to keys but needs to be super careful as we do not know what we might break (in favor: @skinkie; against: @thbar and @TuThoThai)
Option 3: freeze this change for later (e.g., v2.1 as originally suggested by @Aurige in the issue #994) --> less favourable path for consensus but potentially acceptable

@thbar

thbar commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

@ue71603 almost there, but not quite yet. (My message is a bit long, but after all the back-and-forth I think it's worth having the full picture written down in one place.)

1. Why not merge as-is

This PR started as an optimisation (welcome!): removing unique constraints already covered by an xsd:key (#994), which brings validation back to v1.3.1 speed. Lots of changes, but all of a single kind.

Because of the sheer number of changes, though, we missed a few: some removed unique had no matching key. We just need to fix those. Once done, v2.0.1 validates the same as v2.0.0 (neither more nor less, with one deliberate exception below), only faster.

Also, CI needs to be green before merging, and it is currently red because of exactly this (see 🔴 below).

2. Why not keys here

  • The PR is already huge (8k changed lines) and hard to review (we already missed some). Adding keys would still mean ~8k lines, but this time mixing two kinds of changes, which is even harder to review.
  • Turning a unique into a key changes what validates, and that feels too risky to us for a patch release.

It is perfectly fine for v2.1 though, where bigger changes are coming anyway (#1034).

3. What remains to roll back (rejected by v2.0.0, accepted by this PR in its current state):

EDIT: still to be verified, but to get an overall idea; I think @Aurige has feedback on that to be posted soon too.

  • GroupOfLinkSequences: publication (🔴 CI) + timetable
  • ValidBetween: publication (🔴 CI) + timetable
  • ValidityPeriod: publication (🔴 CI)
  • TemplateVehicleJourney: publication + timetable
  • SectionInSequence: timetable

🔴 = already proven by the should-fail examples, and the reason CI is red. The others were found by testing further (happy to share the test files).

(CalendarDate was lost too, but as discussed with @Aurige that constraint was wrong in the first place, so we're fine leaving it out.)

Each one is an exact revert from v2.0. It can be done directly on this branch (as @TuThoThai proposed) or via a sister PR, whichever is easier. Ideally with should-fail cases, but I can live without them if we want.

@Aurige

Aurige commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

I found other issues to confirm & complement @thbar 's list

Unique to keep Why it must not be removed
GroupOfLinkSequences_UniqueBy_Id_Version No key on this element. It is the only identity constraint → essential.
Equipment_UniqueBy_Id_Version Special case: Equipment is abstract="true", so the constraint is empty (no node matches it !!). Safe to remove, but no key covers it (the large Equipment_AnyVersionedKey only lists the concrete subtypes).
JourneyFrequencyGroup_UniqueBy_Id_Version Only HeadwayJourneyGroup has a key; JourneyFrequencyGroup has none. It is the only identity constraint → essential.
TemplateVehicleJourney_UniqueBy_Id_Version No key on this element. It is the only identity constraint → essential.
SectionInSequence_UniqueBy_Id_Version_Order In the timetable file, no key on SectionInSequence (the key only exists in NeTEx_publication.xsd). In timetable, it is the only identity constraint.
TimingLinkInJourneyPattern_UniqueBy_Id_Version_Order Selector typo (_ordered is not an element): empty constraint, can be removed. But it is not covered by any key; the real element TimingLinkInJourneyPattern does have a key in this file.
ResponsibilitySet_UniqueBy_Id_Version Cross-subtype uniqueness: the key covers ResponsibilitySet | DefaultResponsibilitySet, not DelegatedResponsibilitySet. Separate keys would not prevent a ResponsibilitySet and a DelegatedResponsibilitySet from sharing the same id.
PointOnLink_UniqueBy_Id_Version Cross-type uniqueness over 3 subtypes; the key only covers PointOnLink (no key for StartPointOnLink/EndPointOnLink).
PassengerEntrance_UniqueBy_Id_Version Cross-type uniqueness over 3 subtypes; the existing keys cover PassengerEntrance alone and PassengerEntrance | DeckVehicleEntrance | OtherDeckEntrance — none covers FromDeckEntrance/ToDeckEntrance.
ValidityCondition_UniqueBy_Id_Version The key has AvailabilityCondition instead of ValidBetween: the unions differ, so cross-uniqueness with ValidBetween is not covered.
UsageValidityPeriod Cross-type uniqueness between the two types; the key only covers UsageValidityPeriod, there is no key on ValidityPeriod.
OperatingDay_UniqueCalendarDateInCalendar A date may appear only once per calendar. No key covers CalendarDate.

@skinkie

skinkie commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

It feels I am reading LLM generated stuff. Vague wording contradicting what has written.

@thbar

thbar commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

@skinkie now you're discussing the form rather than the substance.

I do use an LLM sometimes to edit my English. The arguments and measurements are mine, though.

The substance, once more:

  • 51b79ea removed 891 unique constraints. About 15 of them (under 2%) had no matching key. For an 8k-line change, that's a good hit rate, and nobody is blaming you for it.
  • 8 remain to roll back to their v2.0.0 form: the 3 already proven by CI, plus 5 more found by testing further (test files available).
  • Once these 8 are rolled back, this is good for production as far as I'm concerned.

Keys are fine with me & @TuThoThai, in v2.1 (#1034). Turning a unique into a key changes what validates, which is not something we want in a patch release.

@skinkie

skinkie commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@thbar parse the descriptions within the table of @Aurige. It is full of contradictions.

Special case: Equipment is abstract="true", so the constraint is empty (no node matches it !!). Safe to remove, but no key covers it (the large Equipment_AnyVersionedKey only lists the concrete subtypes).

Only HeadwayJourneyGroup has a key; JourneyFrequencyGroup has none. It is the only identity constraint → essential.

In the timetable file, no key on SectionInSequence (the key only exists in NeTEx_publication.xsd). In timetable, it is the only identity constraint.

@thbar

thbar commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

@skinkie yes, there is AI in @Aurige's table, as in my edits. What matters is whether it holds up, so I checked each row against the schemas:

Once #1110 is merged into this branch, this is good to go.

* should-fail: support per-case schema (timetable) and GitHub annotations

* should-fail: duplicate TemplateVehicleJourney (publication)

* should-fail: duplicate GroupOfLinkSequences (timetable)

* should-fail: duplicate ValidBetween (timetable)

* should-fail: duplicate TemplateVehicleJourney (timetable)

* should-fail: duplicate SectionInSequence (timetable)

* rollback: restore GroupOfLinkSequences unique to v2.0 state (publication)

* rollback: restore ValidityCondition unique to v2.0 state (publication)

* rollback: restore UsageValidityPeriod unique to v2.0 state (publication)

* rollback: restore TemplateVehicleJourney unique to v2.0 state (publication)

* rollback: restore GroupOfLinkSequences unique to v2.0 state (timetable)

* rollback: restore ValidityCondition unique to v2.0 state (timetable)

* rollback: restore SectionInSequence unique to v2.0 state (timetable)

* rollback: restore TemplateVehicleJourney unique to v2.0 state (timetable)

* should-fail: duplicate CalendarDate (publication)

* rollback: restore OperatingDay CalendarDate unique to v2.0 state (publication)

* rollback: restore OperatingDay CalendarDate unique to v2.0 state (timetable)
@TuThoThai
TuThoThai merged commit 11d40b5 into v2.0 Nov 17, 2026
2 checks passed
@TuThoThai
TuThoThai deleted the v2_remove_unique branch November 17, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hygiene Technical dept, results in a breaking change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redundant "key" and "unique" constraints

6 participants