MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / stmt_cache_put_int

Function stmt_cache_put_int

db/sql_stmt_cache.c:513–585  ·  view source on GitHub ↗

return code of 1 means we encountered an error and the caller * needs to cleanup this rec->stmt */

Source from the content-addressed store, hash-verified

511/* return code of 1 means we encountered an error and the caller
512 * needs to cleanup this rec->stmt */
513int stmt_cache_put_int(struct sqlthdstate *thd, struct sqlclntstate *clnt,
514 struct sql_state *rec, int noCache, int outrc,
515 int distributed)
516{
517 if (noCache) {
518 goto cleanup;
519 }
520 if (gbl_enable_sql_stmt_caching == STMT_CACHE_NONE) {
521 goto cleanup;
522 }
523 if (distributed || clnt->conns || clnt->plugin.state) {
524 goto cleanup;
525 }
526 if (thd && thd->authState.numDdls > 0) { /* NOTE: Never cache DDL. */
527 goto cleanup;
528 }
529 if (dont_cache_this_sql(rec)) {
530 goto cleanup;
531 }
532 sqlite3_stmt *stmt = rec->stmt;
533 if (stmt == NULL) {
534 goto cleanup;
535 }
536 if (gbl_enable_sql_stmt_caching == STMT_CACHE_PARAM &&
537 param_count(clnt) == 0) {
538 goto cleanup;
539 }
540 if (bdb_attr_get(thedb->bdb_attr, BDB_ATTR_DISABLE_CACHING_STMT_WITH_FDB) &&
541 sqlite3_stmt_has_remotes(stmt)) {
542 goto cleanup;
543 }
544
545 if (rec->status & (CACHE_FOUND_STMT | CACHE_FOUND_STR)) { /* we found this stmt in the cache */
546 if (rec->stmt_entry == NULL) {
547 query_data_func(clnt, NULL, NULL, QUERY_HINT_DATA, QUERY_DATA_SET);
548 } else {
549 if (rec->status & CACHE_HAS_HINT) {
550 /* Leave the ownership of stmt data. */
551 query_data_func(clnt, NULL, NULL, QUERY_STMT_DATA, QUERY_DATA_SET);
552 }
553 if (stmt_cache_requeue_old_entry(thd->stmt_cache, rec->stmt_entry)) { /* put back in queue... */
554 stmt_cache_finalize_entry(rec->stmt_entry); /* ...and on error, cleanup */
555 }
556 return 0;
557 }
558 }
559
560 /* this is a new stmt (never was in cache before) so create cache object */
561 const char *sqlptr = clnt->sql;
562 if (rec->sql)
563 sqlptr = rec->sql;
564
565 if (rec->status & CACHE_HAS_HINT) {
566 sqlptr = rec->cache_hint;
567 if (!(rec->status & CACHE_FOUND_STR)) {
568 void *data = NULL;
569 int data_sz = 0;
570 query_data_func(clnt, &data, &data_sz, QUERY_HINT_DATA, QUERY_DATA_GET);

Callers 1

Calls 11

dont_cache_this_sqlFunction · 0.85
param_countFunction · 0.85
bdb_attr_getFunction · 0.85
sqlite3_stmt_has_remotesFunction · 0.85
query_data_funcFunction · 0.85
add_sql_hint_tableFunction · 0.85
stmt_cache_add_new_entryFunction · 0.85
stmt_cache_remove_entryFunction · 0.85
stmt_cache_free_entryFunction · 0.85

Tested by

no test coverage detected