<div>I attempted to find all orphan current_way_nodes, which have no current_node, and are causing the constraint to fail:</div><div><br></div><div>SELECT * FROM current_way_nodes LEFT JOIN current_nodes ON <a href="http://current_nodes.id">current_nodes.id</a> = current_way_nodes.node_id WHERE <a href="http://current_nodes.id">current_nodes.id</a> IS NULL</div>
<div><br></div><div>This seems to hang, but perhaps I just need to let it run for a long time. I tried formulating this query a few different ways but it seems that since it cannot use an index on <a href="http://current_nodes.id">current_nodes.id</a>, the query must necessarily be quite slow. If you limit by id, you can get some results:</div>
<div><br></div><div>SELECT * FROM current_way_nodes LEFT JOIN current_nodes ON <a href="http://current_nodes.id">current_nodes.id</a> = current_way_nodes.node_id WHERE <a href="http://current_way_nodes.id">current_way_nodes.id</a> < 10000 AND <a href="http://current_nodes.id">current_nodes.id</a> IS NULL</div>
<div><br></div><div>yields several current_way_nodes in the planet dump which don't have current_node counterparts:</div><div><br></div><div>current_way_nodes:</div><div>id;node_id;sequence_id</div><div><div>650;420418211;1</div>
<div>650;420418214;2</div><div>650;420418213;3</div><div>650;420418212;4</div><div>2477;411393928;2</div><div>2477;411371802;4</div><div><br></div><div>And I traced the lifecycle of a couple records that violated the foreign key constraint (left a current_way_node as an orphan) and found this:</div>
<div><div><br></div><div><span class="Apple-style-span" style="font-size: x-small;"><br></span></div><div><span class="Apple-style-span" style="font-size: x-small;"><?xml version="1.0" encoding="UTF-8"?></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"><osm version="0.6" generator="OpenStreetMap server"></span></div><div><span class="Apple-style-span" style="font-size: x-small;"> <node id="17704640" lat="51.5465346" lon="-2.4116768" changeset="127793" user="southglos" uid="3937" visible="true" timestamp="2006-10-06T11:08:17Z" version="1"></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"> <tag k="created_by" v="JOSM"/></span></div><div><span class="Apple-style-span" style="font-size: x-small;"> </node></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"> <node id="17704640" lat="51.5465346" lon="-2.4116768" changeset="601639" user="Strange but untrue" uid="57932" visible="true" timestamp="2009-04-16T22:28:59Z" version="2"/></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"> <node id="17704640" lat="51.5465346" lon="-2.4116768" changeset="601639" user="Strange but untrue" uid="57932" visible="true" timestamp="2009-04-16T22:31:23Z" version="3"/></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"> <node id="17704640" lat="51.5465346" lon="-2.4116768" changeset="601639" user="Strange but untrue" uid="57932" visible="true" timestamp="2009-04-16T22:32:07Z" version="4"/></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"> <node id="17704640" lat="51.5465346" lon="-2.4116768" changeset="601639" user="Strange but untrue" uid="57932" visible="true" timestamp="2009-04-16T22:32:19Z" version="5"/></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"> <node id="17704640" lat="51.5465346" lon="-2.4116768" changeset="601639" user="Strange but untrue" uid="57932" visible="false" timestamp="2009-04-16T22:32:21Z" version="6"/></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"></osm></span></div><div><span class="Apple-style-span" style="font-size: x-small;"><br></span></div><div><span class="Apple-style-span" style="font-size: x-small;"><?xml version="1.0" encoding="UTF-8"?></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"><osm version="0.6" generator="OpenStreetMap server"></span></div><div><span class="Apple-style-span" style="font-size: x-small;"> <node id="17704638" lat="51.5454224" lon="-2.4112624" changeset="7133" user="southglos" uid="3937" visible="true" timestamp="2007-04-05T16:30:26Z" version="1"></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"> <tag k="created_by" v="JOSM"/></span></div><div><span class="Apple-style-span" style="font-size: x-small;"> </node></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"> <node id="17704638" lat="51.5454224" lon="-2.4112624" changeset="601639" user="Strange but untrue" uid="57932" visible="true" timestamp="2009-04-16T22:28:58Z" version="2"/></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"> <node id="17704638" lat="51.5454224" lon="-2.4112624" changeset="601639" user="Strange but untrue" uid="57932" visible="true" timestamp="2009-04-16T22:31:22Z" version="3"/></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"> <node id="17704638" lat="51.5454224" lon="-2.4112624" changeset="601639" user="Strange but untrue" uid="57932" visible="true" timestamp="2009-04-16T22:32:07Z" version="4"/></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"> <node id="17704638" lat="51.5454224" lon="-2.4112624" changeset="601639" user="Strange but untrue" uid="57932" visible="true" timestamp="2009-04-16T22:32:18Z" version="5"/></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"> <node id="17704638" lat="51.5454224" lon="-2.4112624" changeset="601639" user="Strange but untrue" uid="57932" visible="false" timestamp="2009-04-16T22:32:21Z" version="6"/></span></div>
<div><span class="Apple-style-span" style="font-size: x-small;"></osm></span></div><div><br></div></div></div><div>It does look like these are marked as visible=false, after which their current_node entries are deleted (neither of these two are in the 'current' dataset anymore). For these offending nodes, the current_way_node entries were not also deleted. This is why i asked if anyone knows how visible=false causes these records to be actually dropped from the current_ tables.</div>
<div><br></div><div>So that's my best guess at how this happens. Is it a problem? Not for me, I guess, but as you said, some applications may continue to take action on this data and future corruption could perhaps occur.</div>
<div><br></div><div>Best,</div><div>Jeff</div><div><br></div><div><br><br><div class="gmail_quote">On Wed, Jul 8, 2009 at 8:00 PM, Joachim Zobel <span dir="ltr"><<a href="mailto:jz-2008@heute-morgen.de">jz-2008@heute-morgen.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Am Dienstag, den 07.07.2009, 18:50 -0400 schrieb Jeffrey Warren:<br>
<div class="im">> No, the data is not corrupt, nor are there duplicate entries. Quite a<br>
> few current_way_nodes are not getting deleted when they cease to be<br>
> 'current', that is, once they're only<br>
> history and no longer part of the current planet.<br>
<br>
</div>Ah, I see. It's not corruption, it's just invalid data hanging around :)<br>
<br>
How can this happen? current_way_nodes has foreign keys on current_ways<br>
and current_nodes.<br>
<div class="im"><br>
> I asked earlier about what mechanism actually deletes<br>
> current_way_nodes if marked for deletion (i think the tag<br>
> is 'visible=false' but i might be mistaken) but nobody seemed to know<br>
<br>
</div>Are you shure that visible=false means "marked for deletion".<br>
current_way_nodes do not have any such flag, only current_ways and<br>
current_nodes have that.<br>
<br>
> - it seems the best route is to go through and delete those orphans,<br>
<div class="im">> but I couldn't write a single SQL query to do so efficiently and<br>
> before writing a script to do it, I realized that the rails port<br>
> doesn't really care if they're there, or if the constraint is<br>
> created.<br>
<br>
</div>Applikations do in general work without constraints. They just tend to<br>
corrupt data. Once the data is corrupt, applications start to behave<br>
weird.<br>
<br>
Please note that I do not understand the ways of the API, I just started<br>
to answer because you seemed to have a database problem (I do understand<br>
databases). The above answer results from just applying some "database<br>
common sense".<br>
<br>
Maybe someone who does understand the API can answer this.<br>
<br>
If you need an SQL statement, just state the query in english, that<br>
should be easily doable.<br>
<br>
Sincerely,<br>
<font color="#888888">Joachim<br>
<br>
<br>
</font></blockquote></div><br></div>