Skip to content

Commit 6b0f657

Browse files
committed
new test case with bind marker and literal
1 parent 8a70ced commit 6b0f657

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/java/org/apache/cassandra/db/guardrails/Guardrails.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,13 @@ public final class Guardrails implements GuardrailsMBean
617617
what, value, isWarning ? "warning" : "failure", threshold));
618618

619619
/**
620-
* Prevents heap exhaustion caused by the anti-pattern of preparing queries with
620+
* Prevents cache overflow and eviction caused by the anti-pattern of preparing queries with
621621
* hardcoded literals instead of bind markers. This prevents filling the statement cache with non-reusable entries.
622622
*/
623623

624624
public static final EnableFlag mispreparedStatementsEnabled =
625625
new EnableFlag("misprepared_statements_enabled",
626-
"misprepared statements cause server-side memory exhaustion and high GC pressure by flooding the statement cache with non-reusable query entries",
626+
"misprepared statements create non-reusable query entries and cause cache overflow",
627627
state -> CONFIG_PROVIDER.getOrCreate(state).getMispreparedStatementsEnabled(),
628628
"misprepared statements");
629629

src/java/org/apache/cassandra/db/guardrails/GuardrailsConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public interface GuardrailsConfig
408408

409409
/**
410410
* <p>
411-
* A statement is considered "mis-prepared" if it contains hardcoded literal values
411+
* A statement is considered "mis-prepared" if it contains only hardcoded liter values and without any bind markers
412412
* instead of bind markers. This is a performance anti-pattern because it prevents
413413
* query plan reuse and floods the server-side Prepared Statement Cache with
414414
* unique entries, leading to heap exhaustion and high GC pressure.

test/unit/org/apache/cassandra/cql3/MispreparedStatementsTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,20 @@ public void testMultiTableBatchGuardrailAllLiteral()
219219
}
220220

221221
@Test
222-
public void testProperlyPreparedWithBindMarkers()
222+
public void testSucceedWithOnlyBindMarkers()
223223
{
224224
assertGuardrailPassed(String.format("SELECT * FROM %s WHERE id = ? AND name = ?", currentTable()));
225225
assertNoWarnings();
226226
}
227227

228+
@Test
229+
public void testSucceedWithOneBindMarkerOneLiteral()
230+
{
231+
232+
assertGuardrailPassed(String.format("SELECT * FROM %s WHERE id = ? AND name = 'v1'", currentTable()));
233+
assertNoWarnings();
234+
}
235+
228236
@Test
229237
public void testSelectAllPasses()
230238
{

0 commit comments

Comments
 (0)