Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to re-prepare cached statements #382

Closed
deblockt opened this issue Jan 20, 2021 · 1 comment
Closed

Add support to re-prepare cached statements #382

deblockt opened this issue Jan 20, 2021 · 1 comment
Labels
type: enhancement A general enhancement

Comments

@deblockt
Copy link

Bug Report

Prepare statement fail when database schema is updated

Versions

  • Driver: 0.8.6-RELEASE
  • Database: postgres
  • Java: 11
  • OS: docker - alpine

Current Behavior

When the database change (exemple column type from VARCHAR(55) to VARCHAR(70)) the existing prepared statement return "cached plan must not change result type"

Stack trace
Error: SEVERITY_LOCALIZED=ERROR, SEVERITY_NON_LOCALIZED=ERROR, CODE=0A000, MESSAGE=cached plan must not change result type, FILE=plancache.c, LINE=716, ROUTINE=RevalidateCachedQuery

Table schema

Input Code
CREATE TABLE public.applied_message (
	id varchar(50) NOT NULL,
	CONSTRAINT pk_applied_message PRIMARY KEY (id)
);
-- run you application who perform insert into applied_message values ('A')

ALTER TABLE applied_message ALTER COLUMN id TYPE varchar(75) USING id::varchar;

Steps to reproduce

Input Code
// using spring driver to perform request 
// run 
this.databaseClient
            .insert()
            .into("applied_message")
            .value("id", eventId)
            .then()
// update the database id column
// run 
this.databaseClient
            .insert()
            .into("applied_message")
            .value("id", eventId)
            .then()
// the error Error: SEVERITY_LOCALIZED=ERROR, SEVERITY_NON_LOCALIZED=ERROR, CODE=0A000, MESSAGE=cached plan must not change result type, FILE=plancache.c, LINE=716, ROUTINE=RevalidateCachedQuery will happen

Expected behavior/code

Don't fail and refresh the prepared statement.
I don't know if the refresh should be done by the postgres driver or by spring or if it should be managed by each application.

@deblockt deblockt added the status: waiting-for-triage An issue we've not yet triaged label Jan 20, 2021
@mp911de
Copy link
Collaborator

mp911de commented Feb 18, 2021

Paging @davecramer. Sounds as if we need to discard the prepared statement and re-prepare it.

@mp911de mp911de changed the title cached plan must not change result type Cached prepared statements are not re-prepared Oct 26, 2021
@mp911de mp911de added the type: enhancement A general enhancement label Oct 26, 2021
@mp911de mp911de changed the title Cached prepared statements are not re-prepared Add support to re-prepare cached statements Oct 26, 2021
@mp911de mp911de removed the status: waiting-for-triage An issue we've not yet triaged label Oct 26, 2021
mp911de added a commit that referenced this issue Oct 26, 2021
We now reprepare cached queries that were invalidated due to e.g. schema changes.

[closes #382]

Signed-off-by: Mark Paluch <mpaluch@vmware.com>
@mp911de mp911de added this to the 0.8.11.RELEASE milestone Oct 26, 2021
mp911de added a commit that referenced this issue Oct 27, 2021
This helps with cache hygiene. Also, reduce allocations.

[#382]

Signed-off-by: Mark Paluch <mpaluch@vmware.com>
mp911de added a commit that referenced this issue Oct 27, 2021
This helps with cache hygiene. Also, reduce allocations.

[#382]

Signed-off-by: Mark Paluch <mpaluch@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants