pietermartin / sqlg

TinkerPop graph over sql

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem working with Topology for indexes

ktschmidt opened this issue · comments

I have some code that uses Topology to create the graph schema based on an externally defined model.  This includes ensuring the vertex/edge labels exist along with their properties, and also creates/removes indexes per the external model.

I've run into a problem when an index is created, then removed, then created again.  Here is the sequence (done in Gremlin Console but should work from Java too, problem first observed in Java) and some observations.

Starting with a fresh graph, ensure a vertex with one indexed property exists.

                topology = graph.getTopology();
              props = new TreeMap<>();
                props.put("brand", org.umlg.sqlg.structure.PropertyType.STRING);
                vLabel = topology.ensureVertexLabelExist("Car", props);
                indexed = new ArrayList<>(1);
                indexed.add(vLabel.getProperties().get("brand"));
                vLabel.ensureIndexExists(IndexType.NON_UNIQUE, indexed);
                graph.tx().commit();

At this point, all is fine, a "V_Car" table has been created with a "brand" column that has an index.  Further, in the sqlg_schema, there is one row in each of the V_vertex, V_property, and V_index tables as expected.

I can then remove the index with the following:

                for (Index index : vLabel.getIndexes().values()) {
                    PropertyColumn prop = index.getProperties().get(0);

                    if ("brand".equals(prop.getName())) {
                        index.remove();
                        break;
                    }
                }
                graph.tx().commit();

After this, the "V_Car" table still has the "brand" column but no longer has the index.  All is good?  Well, checking the sqlg_schema tables, V_vertex still has a row, the index row has been removed, but the property row has also been removed which seems wrong as it is not what was asked (just index removal was done, not property removal) and is inconsistent with the V_Car table

If I then execute the code to ensure the vertex and index again, I get an error on the ensureIndexExists call:

Property brand for AbstractLabel public.Car does not exists

So the missing property causes an issue here, and seemingly wasn't recreated with the ensureVertexLabelExist call.

I would expect the sequence done above to result in the property and index being created again.

Fixed on the 2020 branch. It was for some unknown reason deleting the sqlg property also.