mirror of https://github.com/apache/cassandra
Merge branch cassandra-2.2 into cassandra-3.0
This commit is contained in:
commit
833c993b8e
|
|
@ -26,6 +26,7 @@ Merged from 2.2:
|
|||
* Fix queries updating multiple time the same list (CASSANDRA-13130)
|
||||
* Fix GRANT/REVOKE when keyspace isn't specified (CASSANDRA-13053)
|
||||
Merged from 2.1:
|
||||
* Fix 2ndary index queries on partition keys for tables with static columns CASSANDRA-13147
|
||||
* Fix ParseError unhashable type list in cqlsh copy from (CASSANDRA-13364)
|
||||
|
||||
3.0.12
|
||||
|
|
|
|||
|
|
@ -78,6 +78,12 @@ public final class StatementRestrictions
|
|||
*/
|
||||
private RestrictionSet nonPrimaryKeyRestrictions;
|
||||
|
||||
/**
|
||||
* <code>true</code> if nonPrimaryKeyRestrictions contains restriction on a regular column,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
private boolean hasRegularColumnsRestriction = false;
|
||||
|
||||
private Set<ColumnDefinition> notNullColumns;
|
||||
|
||||
/**
|
||||
|
|
@ -263,7 +269,13 @@ public final class StatementRestrictions
|
|||
else if (def.isClusteringColumn())
|
||||
clusteringColumnsRestrictions = clusteringColumnsRestrictions.mergeWith(restriction);
|
||||
else
|
||||
{
|
||||
if (restriction.columnDef.kind == ColumnDefinition.Kind.REGULAR)
|
||||
{
|
||||
hasRegularColumnsRestriction = true;
|
||||
}
|
||||
nonPrimaryKeyRestrictions = nonPrimaryKeyRestrictions.addRestriction(restriction);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -337,6 +349,11 @@ public final class StatementRestrictions
|
|||
return this.isKeyRange;
|
||||
}
|
||||
|
||||
public boolean hasRegularColumnsRestriction()
|
||||
{
|
||||
return hasRegularColumnsRestriction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the secondary index need to be queried.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -743,13 +743,14 @@ public class SelectStatement implements CQLStatement
|
|||
ByteBuffer[] keyComponents = getComponents(cfm, partition.partitionKey());
|
||||
|
||||
Row staticRow = partition.staticRow();
|
||||
// If there is no rows, then provided the select was a full partition selection
|
||||
// (i.e. not a 2ndary index search and there was no condition on clustering columns),
|
||||
// If there is no rows, and there's no restriction on clustering/regular columns,
|
||||
// then provided the select was a full partition selection (either by partition key and/or by static column),
|
||||
// we want to include static columns and we're done.
|
||||
if (!partition.hasNext())
|
||||
{
|
||||
if (!staticRow.isEmpty() && (!restrictions.usesSecondaryIndexing() || cfm.isStaticCompactTable())
|
||||
&& !restrictions.hasClusteringColumnsRestriction())
|
||||
if (!staticRow.isEmpty()
|
||||
&& (!restrictions.hasClusteringColumnsRestriction() || cfm.isStaticCompactTable())
|
||||
&& !restrictions.hasRegularColumnsRestriction())
|
||||
{
|
||||
result.newRow(protocolVersion);
|
||||
for (ColumnDefinition def : selection.getColumns())
|
||||
|
|
|
|||
|
|
@ -379,7 +379,7 @@ public abstract class CassandraIndex implements Index
|
|||
|
||||
public void insertRow(Row row)
|
||||
{
|
||||
if (row.isStatic() != indexedColumn.isStatic())
|
||||
if (row.isStatic() && !indexedColumn.isStatic() && !indexedColumn.isPartitionKey())
|
||||
return;
|
||||
|
||||
if (isPrimaryKeyIndex())
|
||||
|
|
|
|||
|
|
@ -1159,6 +1159,29 @@ public class SecondaryIndexTest extends CQLTester
|
|||
row(bytes("foo124"), EMPTY_BYTE_BUFFER));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOnPartitionKeyWithStaticColumnAndNoRows() throws Throwable
|
||||
{
|
||||
createTable("CREATE TABLE %s (pk1 int, pk2 int, c int, s int static, v int, PRIMARY KEY((pk1, pk2), c))");
|
||||
createIndex("CREATE INDEX ON %s (pk2)");
|
||||
execute("INSERT INTO %s (pk1, pk2, c, s, v) VALUES (?, ?, ?, ?, ?)", 1, 1, 1, 9, 1);
|
||||
execute("INSERT INTO %s (pk1, pk2, c, s, v) VALUES (?, ?, ?, ?, ?)", 1, 1, 2, 9, 2);
|
||||
execute("INSERT INTO %s (pk1, pk2, s) VALUES (?, ?, ?)", 2, 1, 9);
|
||||
execute("INSERT INTO %s (pk1, pk2, c, s, v) VALUES (?, ?, ?, ?, ?)", 3, 1, 1, 9, 1);
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk2 = ?", 1),
|
||||
row(2, 1, null, 9, null),
|
||||
row(1, 1, 1, 9, 1),
|
||||
row(1, 1, 2, 9, 2),
|
||||
row(3, 1, 1, 9, 1));
|
||||
|
||||
execute("UPDATE %s SET s=?, v=? WHERE pk1=? AND pk2=? AND c=?", 9, 1, 1, 10, 2);
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk2 = ?", 10), row(1, 10, 2, 9, 1));
|
||||
|
||||
execute("UPDATE %s SET s=? WHERE pk1=? AND pk2=?", 9, 1, 20);
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk2 = ?", 20), row(1, 20, null, 9, null));
|
||||
}
|
||||
|
||||
private ResultMessage.Prepared prepareStatement(String cql, boolean forThrift)
|
||||
{
|
||||
return QueryProcessor.prepare(String.format(cql, KEYSPACE, currentTable()),
|
||||
|
|
|
|||
Loading…
Reference in New Issue