Virtuoso Open-Source Wiki
Virtuoso Open-Source, OpenLink Data Spaces, and OpenLink Ajax Toolkit
Advanced Search
Help?
Location: / Dashboard / Main / VirtTipsAndTricksGuide / VirtTipsAndTricksGuideCreateGraph

What are the differences between create, drop, clear and delete Graph?

What?

What are the differences across DROP, CLEAR, and DELETE FROM options Virtuoso supports.

Why?

Clarifying implications of the options on Virtuoso

How?

In Virtuoso it does not matter whether CREATE GRAPH and DROP GRAPH are called or not. Their purpose is to provide compatibility with the original SPARUL that was designed for Jena. Some Jena triple stores require explicit creation of each graph (like CREATE TABLE in SQL), they report errors if one tries to create a graph twice and so on.

For Virtuoso, a new graph is not an important system event, it has single quad store shared by all graphs. When a graph is made by CREATE GRAPH, its name is placed in an auxiliary table that is used solely to signal appropriate errors on CREATE graph that is CREATE-d already or on DROP of a missing graph; this table is not used in any way in SPARQL or other subsystems. In a perfect world, smart development tools will query that table to give hints to a programmer regarding available graphs, but the reality is not so perfect.

What's more important is a difference between DELETE FROM g { ?s ?p ?o } FROM g WHERE { ?s ?p ?o } and CLEAR GRAPH g , as both will delete all triples from the specified graph <g> with equal speed, but CLEAR GRAPH will also delete free-text index data about occurrences of literals in this specific graph. So CLEAR GRAPH will make the database slightly more compact and the text search slightly faster. (Naturally, DROP GRAPH makes CLEAR GRAPH inside, not just DELETE FROM...)

DROP GRAPH and CLEAR GRAPH equivalence

DROP GRAPH is equivalent of CLEAR GRAPH. It requires initially the graph to be created explicitly.

Note: All SPARQL commands should work via SPARUL ( i.e. executed from the /sparql endpoint) as soon as "SPARQL" user has "SPARQL_UPDATE" privilege.

Assume the following sequence of commands to be executed from the /sparql endpoint:

  1. Create explicitly a graph:

    CREATE GRAPH <qq> callret-0 Create graph <qq> -- done

  2. If you don't know whether the graph is created explicitly or not, use DROP SILENT GRAPH:

    DROP SILENT GRAPH <qq> callret-0 Drop silent graph <qq> -- done

  3. If you know the graph is created explicitly, use DROP GRAPH:

    DROP GRAPH <qq> callret-0 Drop graph <qq> -- done

Related

Powered By Virtuoso