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

PS-9190: JS Stored Routines: basic functionality #5449

Open
wants to merge 8 commits into
base: 8.4
Choose a base branch
from

Conversation

dlenev
Copy link
Contributor

@dlenev dlenev commented Oct 10, 2024

See individual commits for detailed commit descriptions.

…ervice for string does not allow setting charset

(commit 21056bf) from Oracle MySQL 9.0 tree.

Bug#36430572 Bug#36491859: mysql_stored_program service for string does not allow setting charset

- Add services for setting string for argument and return value which supports setting charset. However, for existing string types, the charset which is set at creation is used instead of the one set in these services.
- Set Item name to be empty string for Item_string.

Change-Id: I595a3d6e352af9632bb5473866e1c775f80e15f4
…n't work for non-string types

(commit aabae02) from Oracle MySQL 9.0 tree.

Bug#35517611 HCS-8941 SP string argument get doesn't work for non-string types

- Allocate a buffer from current_thd memroot and copy the string to this buffer. The return value is this buffer.

Change-Id: I831185379fed78698daf95cdf4d60b365d458cb4
…work for non-string types

(commit 632a740) from Oracle MySQL 9.0 tree:

Postfix Bug#35517611: SP string argument get doesn't work for non-string types

Change-Id: Ica4b6d1fb174cb572e79f6b30e5e0b7ce32889fc
@dlenev dlenev changed the title PS-9190: JS Stored Routines: basic functionality Beta PS-9190: JS Stored Routines: basic functionality Oct 10, 2024
https://perconadev.atlassian.net/browse/PS-9190

Implement component that adds to Percona Server for MySQL support
of Stored Functions and Procedures written in JS language or,
more formally, ECMAScript by employing Google's V8 engine.

This is the first commit in a series which implements basic
functionality such as:

- Creation/dropping of JS stored functions and procedures.
- Execution of stored functions/procedures.
- Support for return values for stored functions, IN and OUT parameters for procedures,
  including charset and type mapping/conversions.
- New global dynamic privilege for JS routine creation and its checking.
- Correct isolation of between different security contexts.
MODULE_ONLY
)

target_include_directories(component_js_lang SYSTEM PRIVATE ${BOOST_PATCHES_DIR} ${BOOST_INCLUDE_DIR} ${V8_INCLUDE_DIR})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use target_link_libraries(component_js_lang extra::boost) for Boost directories (patches are handled by the CMake interface library)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally it would be nice to have v8.cmake similar to, say, boost.cmake where we check all the provided directories (V8_INCLUDE_DIR and V8_LIB_DIR ) and creates an interface library extra::v8.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed on Slack - instead of using extra::boost I have opted for removing dependency on Boost for now, since It turned out that code only used BOOST_PP_STRINGIZE() and even that turned out to be not really necessary.

components/js_lang/js_lang_core.h Show resolved Hide resolved
components/js_lang/js_lang_core.h Show resolved Hide resolved
mysql_cstring_with_length sql_command;
always_ok(mysql_service_mysql_thd_attributes->get(m_thd, "sql_command",
&sql_command));
return (strcmp(sql_command.str, "create_procedure") == 0 ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not take into account that sql_command.length.
May be std::string_view(sql_command.str, sql_command.length) == "create_procedure"

components/js_lang/js_lang_core.h Show resolved Hide resolved
components/js_lang/js_lang_core.h Show resolved Hide resolved
components/js_lang/js_lang_param.cc Show resolved Hide resolved
return mysql_service_mysql_stored_program_return_value_unsigned_int->set(
nullptr, value);
}
static bool set_param_string(uint /* idx */, const char *string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider std::string_view instead of (string, length) pair

components/js_lang/js_lang_param.cc Outdated Show resolved Hide resolved
components/js_lang/js_lang_param.cc Outdated Show resolved Hide resolved
@retval False - Success.
@retval True - Failure.
*/
DECLARE_BOOL_METHOD(copy_convert,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this taken from 9.x or this is just a missing piece you needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't take this from 9.x, there is no such functionality there.
So this is a missing piece I had to implement myself to support non-UTF8 parameters to JS routines.

First pack of post-review fixes.
Second pack of post-review fixes.
Third pack of post-review fixes.
Fourth pack of post-review fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants